vb.net 动态填加按钮,点击按钮时在TextBox1中显示被点击的按钮名如button1
1个回答
展开全部
'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
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
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询