从数据库加载动态保存的按钮

时间:2014-01-21 02:04:17

标签: .net database vb.net button

我真的无法弄清楚我将如何编写流程代码。

For Each dtrow In camBtnDtable.Rows
    Dim cameraNumber = camBtnDtable.Select("ButtonName =" & " '" & "foo" & "'")(0)("cameraID")
    Dim nBtn As New Button

    nBtn.Text = "C-" & 'this should be cameraNumber e.g "C-01"
    nBtn.Name = 'select from the database, I don't know if this is still important though
    nBtn.Location = 'select x and y from database where name is this

    AddHandler nBtn.Click, AddressOf nBtn_Click

    picture.Controls.Add(nBtn)
Next

这是一个混乱的代码,但一般来说,我想要的是从访问数据库加载按钮的属性。

1 个答案:

答案 0 :(得分:1)

Dim Btn as Button

' assumes the camBtnDtable is something Like Select * from buttons
For Each dtRow in camBtnDtable.Rows
    Btn = New Button

    Btn.Name = dtRow.CameraButtonNameColumn
    Btn.Text = dtRow.CameraButtonTextColumn
    Btn.Location = dtRow.CameraButtonLocationColumn
    ' or
    Btn.Location = New Point(dtRow.CameraButtonXColumn, 
                             dtRow.CameraButtonYColumn)

    picture.Controls.Add(Btn)   ' ??? picture?  not form?

    AddHandler nBtn.Click, AddressOf nBtn_Click
 Next
  1. 不知道列名
  2. 不知道db schema
  3. 不知道你为按钮存储了什么(即位置与X,Y)
  4. 不知道为什么要解析名称,道具应按原样存储并在不处理的情况下进行恢复
  5. 单行将包含按钮的所有数据,因此只需循环遍历行。