vb.net无法让它在按钮点击时运行脚本

时间:2013-11-18 11:44:15

标签: vb.net

我创建了一个按钮,但是当我点击时无法让它运行msgbox(“点击”)..我做错了什么? 感谢。

Private Sub main_Load(sender As Object, e As EventArgs) Handles MyBase.Load
With mybut
mybut.AutoSize = True
mybut.Name = "delete-btn" & btn_number
mybut.Location = New System.Drawing.Point(500, 20)
mybut.Text = "Delete"
End With
End Sub

Private Sub mybut_Click(sender As Object, e As EventArgs)
MsgBox("Click")
End Sub

1 个答案:

答案 0 :(得分:1)

点击按钮需要Handles

Private Sub mybut_Click(sender As Object, e As EventArgs) Handles mybut.Click
MsgBox("Click")
End Sub

如果是动态按钮,则需要add an event handler

AddHandler mybut.Click, AddressOf Me.mybut_Click