C
Cary Linkfield
I have a standard form I use. It inherits from Windows.Forms.Form. I
usually add a Cancel button the form in the designer. I want to raise the
Cancel button's Click event when the user presses the escape key.
Public Class myStandardForm
Inherits Windows.Forms.Form
Private WithEvents _btnCancel As Button
Private Sub _Load(ByVal sender As Object, ByVal e As EventArgs) Handles
MyBase.Load
MyBase.KeyPreview = True
If Not IsNothing(MyBase.CancelButton) Then
_btnCancel = MyBase.CancelButton
End If
End Sub
Protected Overrides Function ProcessCmdKey(ByRef msg As Message, ByVal
keyData As Keys) As Boolean
If keyData = Keys.Escape Then
' ******* here is where I would like to raise _btnCancel.Click
End if
End Function
End Class
Public Class myCustomForm
Inherits myStandardForm
Friend WithEvents btnCancel As System.Windows.Forms.Button
Me.CancelButton = Me.btnExit
Me.Controls.Add(Me.btnExit)
Private Sub btnExit_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles btnExit.Click
' ************ Sometimes I do special things here.
' ************ I want this code to execute as a result
' ************ of raising the Click event, which happens
' ************ as a result of pressing the Escape key
Me.Close()
End Sub
End Class
usually add a Cancel button the form in the designer. I want to raise the
Cancel button's Click event when the user presses the escape key.
Public Class myStandardForm
Inherits Windows.Forms.Form
Private WithEvents _btnCancel As Button
Private Sub _Load(ByVal sender As Object, ByVal e As EventArgs) Handles
MyBase.Load
MyBase.KeyPreview = True
If Not IsNothing(MyBase.CancelButton) Then
_btnCancel = MyBase.CancelButton
End If
End Sub
Protected Overrides Function ProcessCmdKey(ByRef msg As Message, ByVal
keyData As Keys) As Boolean
If keyData = Keys.Escape Then
' ******* here is where I would like to raise _btnCancel.Click
End if
End Function
End Class
Public Class myCustomForm
Inherits myStandardForm
Friend WithEvents btnCancel As System.Windows.Forms.Button
Me.CancelButton = Me.btnExit
Me.Controls.Add(Me.btnExit)
Private Sub btnExit_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles btnExit.Click
' ************ Sometimes I do special things here.
' ************ I want this code to execute as a result
' ************ of raising the Click event, which happens
' ************ as a result of pressing the Escape key
Me.Close()
End Sub
End Class