Reputation: 4655
I have a situation with a usercontrol which contains only one textbox and which is substantially different from the behavior in VB6.
Necessity is that in certain circumstances to cancel key.Down of usercontrol mentioned that it does not fire this event (in an external program).
There I tried to put to _KeyDown event handler of textbox in usercontrol e.handled = true and e.suppressKeyPress = true but with no results.
Usercontrol still emits KeyDown event with a keystroke.
Private Sub myText_KeyDown(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles myText.KeyDown
If e.KeyCode = Keys.Down Then
If stop_Down Then 'property
e.Handled = True
e.SuppressKeyPress = True
Exit Sub
End If
End If
Program passes through this code properly regarding of properties.
But don't suppress _KeyDown event for usercontrol.
How to suppress _KeyDown event to be fired from usercontrol in situation showed in upper code?
Upvotes: 0
Views: 1236
Reputation:
You can override the ProcessCmdKey
function. This is the first function in a chain that receives key strokes.
Return true and the rest of the chain will not receive the stroke.
For example (for the user control):
Protected Overrides Function ProcessCmdKey(ByRef msg As Forms.Message, _
keyData As Forms.Keys) As Boolean
If MyCriteriasToIgnoreStroke Then
Return True
End If
Return MyBase.ProcessCmdKey(msg, keyData)
End function
Upvotes: 1