我正在为基于POS的触摸屏开发项目 我想知道如何在运行时添加按钮,具体取决于存储在数据库中的项目数 以及如何在Container(Panel或FlowlayoutPanel)中对齐和显示这些按钮? 这段代码我用它来创建一个按钮:
Dim newbtn As New Button
Me.Controls.Add(newbtn)
AddHandler newbtn.Click, AddressOf newbtn_mouseup
答案 0 :(得分:1)
我发现这个解决方案:
If Cn.State = 1 Then Cn.Close()
If Rs.State = 1 Then Rs.Close()
Cn.Open("Provider=Microsoft.Jet.OLEDB.4.0; Data Source=" & Application.StartupPath & "\rptdb.mdb; Jet OLEDB:Database Password=KNOZ1003")
Rs.Open("Select * From tblunit ", Cn, 1, 2)
For i = 1 To Rs.RecordCount
Dim newbtn As New Button
newbtn.Text = Rs.Fields("unm").Value
newbtn.Size = New Size(100, 50)
TableLayoutPanel1.Controls.Add(newbtn)
Rs.MoveNext()
Next