vb.net 动态填加按钮,点击按钮时在TextBox1中显示被点击的按钮名如button1

如题所述

'vb.net2008
Public Class Form1
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Dim j_MyButton As New ArrayList
For i = 0 To 5
Dim k1 As New Button
k1.SetBounds(20, 22 * i, 100, 20) '设置位置和大小(x y w h)
k1.Visible = True
AddHandler k1.Click, AddressOf my_button '委托点击事件
Me.Controls.Add(k1) '在主窗口内加入控件
j_MyButton.Add(k1)
j_MyButton(i).name = "发现" & i & "个MM"
j_MyButton(i).text = "My butten " & i
Next
End Sub
Private Sub my_button(ByVal sender As System.Object, ByVal e As System.EventArgs)
TextBox1.AppendText(sender.name & vbCrLf)
End Sub
End Class
温馨提示:内容为网友见解,仅供参考
无其他回答
相似回答