vb.net中动态建立了50个button怎么向这50个button中添加click事件

来源:百度知道 编辑:UC知道 时间:2024/06/06 07:42:49
Private Sub Button2_Click_2(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click

Dim y As Integer = 12
Dim x As Integer = 170
For counter As Integer = 1 To 50
button = New Button
button.Parent = Me
button.SetBounds(x, y, 30, 20)
Label1.Text = "14"
button.Text = counter
y += 30
If y > 350 Then
y = 12
x += 100
End If
Next

End Sub
怎么向这五十个里添加click事件,请高手指教一下,本小姐十分感谢

我用VB2008.NET做的一个动态添加3个按钮的实例,请参考
public Class Form1
Dim a(2) As Button

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim x, y As Integer
x += 2
y += 2
For i = 0 To 2
Dim j As New Button
a(i) = j
a(i).Text = "Button" & i.ToString
a(i).Size = New Size(65, 28)
a(i).Location = New Size(x, y)
x = x + 65 + 10
a(i).Name = "button" & i.ToString
Me.Controls.Add(a(i))
Select Case i
Case 0
AddHandler a(i).Click, AddressOf abc
Case 1
AddHandler a(i).Click, AddressOf abc1
Case 2
AddHandler a(i).Click, AddressOf abc2
End Select