Private Sub FrmOrder_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
SqlCmd = "select id,status from tabless"
dsTempCls()
DTset = WebDB.SQLRead(SqlCmd)
Application.DoEvents()
Dim intLoop As Integer
' Off sets
Dim y As Integer = 5
Dim x As Integer = 0
' Loop through buttons
For intLoop = 0 To DTset.Tables(0).Rows.Count - 1
dsTempCls()
dsTemp = WebDB.SQLRead(SqlCmd)
Application.DoEvents()
' Create button and set its width
Dim newbutton As New Button
newbutton.Width = 60
newbutton.Height = 40
' If we have hit 4 buttons, adjust the y value by adding 10 onto the controls height
' Reset x back to 0
If intLoop Mod 3 = 0 Then
' This gives us a 10 pixel buffer below each row of buttons
y += newbutton.Height + 10
x = 0
End If
' Set the text and set its top and left based on its dimensions and count
newbutton.Text = dsTemp.Tables(0).Rows(intLoop).Item("id")
newbutton.Name = dsTemp.Tables(0).Rows(intLoop).Item("id")
newbutton.Top = y
' This gives us a 5 pixel right buffer between buttons
newbutton.Left = 26 + (x * (newbutton.Width + 5))
x += 1
Me.Controls.Add(newbutton)
Next
End Sub
Private Sub FrmOrder_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
SqlCmd = "select id,status from tabless"
dsTempCls()
DTset = WebDB.SQLRead(SqlCmd)
Application.DoEvents()
Dim intLoop As Integer
' Off sets
Dim y As Integer = 5
Dim x As Integer = 0
' Loop through buttons
For intLoop = 0 To DTset.Tables(0).Rows.Count - 1
dsTempCls()
dsTemp = WebDB.SQLRead(SqlCmd)
Application.DoEvents()
' Create button and set its width
Dim newbutton As New Button
newbutton.Width = 60
newbutton.Height = 40
' If we have hit 4 buttons, adjust the y value by adding 10 onto the controls height
' Reset x back to 0
If intLoop Mod 3 = 0 Then
' This gives us a 10 pixel buffer below each row of buttons
y += newbutton.Height + 10
x = 0
End If
' Set the text and set its top and left based on its dimensions and count
newbutton.Text = dsTemp.Tables(0).Rows(intLoop).Item("id")
newbutton.Name = dsTemp.Tables(0).Rows(intLoop).Item("id")
newbutton.Top = y
' This gives us a 5 pixel right buffer between buttons
newbutton.Left = 26 + (x * (newbutton.Width + 5))
x += 1
AddHandler newbutton.Click, AddressOf ButtonClick
Me.Controls.Add(newbutton)
Next
End Sub
Private Sub ButtonClick(ByVal sender As System.Object, ByVal e As System.EventArgs)
MessageBox.show(sender.Name)
'sender คือ Button ที่ส่ง Event ออกมา
'sender เป็น Object จะไม่มีตัวช่วย ถ้าใช้บ่อยในโพรเซส ให้เอา Control เฉพาะมารับก่อน
Dim myButton As Button = sender
End Sub