Vb.net 取消其派生类中的按钮单击事件
最近,我正在开发一个自定义按钮,其中我必须捕获按钮的事件,根据特定条件,我将阻止事件或将其传递到包含自定义按钮的表单上 下面是我正在编写的代码的原型:Vb.net 取消其派生类中的按钮单击事件,vb.net,Vb.net,最近,我正在开发一个自定义按钮,其中我必须捕获按钮的事件,根据特定条件,我将阻止事件或将其传递到包含自定义按钮的表单上 下面是我正在编写的代码的原型: Public Class MyCustomButton Inherits Windows.Forms.Button Private Sub Me_Clicked(ByVal sender As Object, ByVal e As EventArgs) Handles MyBase.Click Dim i As
Public Class MyCustomButton
Inherits Windows.Forms.Button
Private Sub Me_Clicked(ByVal sender As Object, ByVal e As EventArgs) Handles MyBase.Click
Dim i As Integer = MsgBox("Are you sure you want to perform the operation?", MsgBoxStyle.YesNoCancel, "MyApp")
If Not i = 6 Then
'Cancel the event
Else
'Continue with the event
End If
End Sub
End Class
现在,如果在给定的示例中用户选择“否”,我不知道如何阻止事件,不允许它通过。
有什么建议吗?您需要覆盖OnClick事件:
Public Class MyCustomButton
Inherits Button
Protected Overrides Sub OnClick(ByVal e As System.EventArgs)
Dim i As Integer = MsgBox("Are you sure you want to perform the operation?", MsgBoxStyle.YesNoCancel, "MyApp")
If Not i = 6 Then
'Cancel the event
Else
MyBase.OnClick(e)
End If
End Sub
End Class