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

PrivateSubButton2_Click_2(ByValsenderAsSystem.Object,ByValeAsSystem.EventArgs)Handles... 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事件,请高手指教一下,本小姐十分感谢
展开
 我来答
xiangsishu3331
2009-10-12
知道答主
回答量:25
采纳率:0%
帮助的人:0
展开全部
我用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
Next
End Sub
Private Sub abc(ByVal sender As System.Object, ByVal e As System.EventArgs)
MessageBox.Show(sender.Text)
End Sub
Private Sub abc1(ByVal sender As System.Object, ByVal e As System.EventArgs)
MessageBox.Show(sender.Text)
End Sub
Private Sub abc2(ByVal sender As System.Object, ByVal e As System.EventArgs)
MessageBox.Show(sender.Text)
End Sub
End Class
小姐你多大了?
推荐律师服务: 若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询

为你推荐:

下载百度知道APP,抢鲜体验
使用百度知道APP,立即抢鲜体验。你的手机镜头里或许有别人想知道的答案。
扫描二维码下载
×

类别

我们会通过消息、邮箱等方式尽快将举报结果通知您。

说明

0/200

提交
取消

辅 助

模 式