我想动态地在vb.net中创建一个按钮。我正在餐馆的销售点工作。有关它是如何完成的任何想法?它有一个数据库。你对如何建立一个餐厅销售点有任何想法吗?
我尝试搜索一些样本,但找不到合适的流程。
答案 0 :(得分:-1)
Dim PointButton As Point = New Point
Try
cn = MySQLi.MySQLConnectionMobile
Query = "SELECT `table` FROM `last_sync`"
da = New MySqlDataAdapter(Query, cn)
ds = New DataSet
ds.Clear()
da.Fill(ds, Table)
ReDim MyButton(ds.Tables(0).Rows.Count)
Dim one As Integer = 1
For i = 0 To ds.Tables(0).Rows.Count - 1
MyButton(i) = New Button
MyButton(i).Text = ds.Tables(0).Rows.Item(i).Item(0).ToString
MyButton(i).Name = "Table" & one.ToString
MyButton(i).BackColor = Color.Transparent
PointButton.Y = 3
If one = 1 Then
PointButton.X = PointButton.X
Else
PointButton.X = PointButton.X + MyButton(i).Width + 10
End If
MyButton(i).Location = PointButton
DirectCast(main_junk.Panel2, Panel).Controls.Add(MyButton(i))
one += 1
AddHandler MyButton(i).Click, AddressOf main_junk.Button_Click
Next
Catch ex As Exception
MsgBox(ex.Message, MsgBoxStyle.Critical, "Uknow Databases")
End Try
其中main_junk是一个表单。 这一个用于处理程序
Public Sub Button_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)
'YOUR CODE HERE
End Sub