这是我的问题:
我有一个自定义控件,它是一个动态生成按钮的面板(将来它会做足够的事情来控制而不仅仅是一个面板)
我想要做的是包含控件的表单中的事件,该控件允许我处理按钮上的点击。
我该怎么做?
Pd积。 1:更具体地说,我希望能够知道点击了哪个按钮
Pd积。 2:事实上,如果我能够在面板中处理标签更改事件,那就足够了
答案 0 :(得分:1)
您可能正在寻找自定义事件
Public Event ButtonPressed As EventHandler(Of ButtonPressedEventArgs)
Public Class ButtonPressedEventArgs
Inherits EventArgs
Public Property MyButtonNumber As Integer
End Class
点击按钮即可举起活动
Private Sub MyButton1_Click(sender As System.Object,e As System.EventArgs) Handles MyButton1.Click
RaiseEvent ButtonPressed(Me, New ButtonPressedEventArgs() with {.MyButtonNumber = 1}
End Sub
并在适当的时候处理事件:
Private Sub MyControl_ButtonPressed(sender As System.Object,e As ButtonPressedEventArgs) Handles MyControl.ButtonPressed
Select Case e.MyButtonNumber
Case 1
'Do what required
End Select
End Sub
答案 1 :(得分:0)
处理按钮点击事件的代码如下所示:
Friend Sub Button1_click(sender As Object, e As EventArgs)
'your code here
End Sub