I am working with MDIs, and I have an MDI parent and childs. But when I press Ctrl+F4 it closes the MDI child.
I am currently working on KeyEvents to disable Ctrl + F4:
Protected Overrides Function ProcessDialogKey(ByVal keyData As System.Windows.Forms.Keys) As Boolean
Select Case (keyData)
Case Keys.Control Or Keys.F4
Return True
Case Keys.Control
Return True
End Select
Return MyBase.ProcessDialogKey(keyData)
End Function
I can't get this working for me... How can I fix it?.
Wrong method, it isn't a dialog. And be sure you put it in the MDI parent form, not the child. This works:
Protected Overrides Function ProcessCmdKey(ByRef msg As Message, ByVal keyData As Keys) As Boolean
If keyData = (Keys.Control Or Keys.F4) Then Return True
Return MyBase.ProcessCmdKey(msg, keyData)
End Function
Related
Please help me figure out for Shift+F10 in VB.NET, Escape and F1 work but Shift+F10 doesn’t work.
Here’s my code:
Protected Overrides Function ProcessCmdKey(ByRef msg As System.Windows.Forms.Message, ByVal keyData As System.Windows.Forms.Keys) As Boolean
Select Case keyData
Case Keys.Escape
Me.Dispose()
Case Keys.F1
MsgBox("You have pressed F1")
Case Keys.ShiftKey = Keys.F10
MsgBox("You have pressed Shift+F10")
Case Else
Return MyBase.ProcessCmdKey(msg, keyData)
End Select
Return True
End Function
You can use
Case Keys.F10 + Keys.Shift
MsgBox("You have pressed Shift+F10")
Result:
I made a MyTextMain custom control
I added the property:
Public Property PressedEscape As Boolean = False
and
Private Sub MyTextMain_KeyUp (ByVal sender As Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles Me.KeyUp
If e.KeyCode = Keys.Escape Then Me.PressedEscape = True
End Sub
However, when I add a TextBox to any new form, the focus is on that control, I press ESC and the property does not change.
I tried the KeyPreview property of the form with True and False and the same.
Where is the error?
Override the ProcessCmdKey in your custom TextBox control:
Protected Overrides Function ProcessCmdKey(ByRef msg As Message, keyData As Keys) As Boolean
If keyData = Keys.Escape Then
Me.PressedEscape = True
End If
Return MyBase.ProcessCmdKey(msg, keyData)
End Function
Making PressedEscape a property seems like an odd choice. I would re-think that depending on what you are doing with it.
I am trying to use the left and right arrow keys to do performclick on my back and next buttons. Here's the code:
Protected Overrides Function ProcessCmdKey(ByRef msg As Message, ByVal keyData As Keys) As Boolean
If keyData = Keys.Left Then
Me.cmdPrevQ.PerformClick()
Return True
End If
If keyData = Keys.Right Then
Me.cmdNextQ.PerformClick()
Return True
End If
Return MyBase.ProcessCmdKey(msg, keyData)
End Function
I want this function to only work as soon as I click on a listview item and not on formload but I don't know how to do that :(
I tried the KeyDown event for my listview but what happens is even if I haven't clicked on anything in my listview and I press on the left or right arrow keys, it gives me an error as my next and back buttons rely on the items inside my listview.
Please help
Using a derived class, I capture the key on a DataGridView and process it as a TAB key. (No issue).
Protected Overrides Function ProcessCmdKey(ByRef msg As System.Windows.Forms.Message, ByVal keyData As System.Windows.Forms.Keys) As Boolean
If keyData = Keys.Return Then
keyData = Keys.Tab
With msg
.WParam = Keys.Tab
End With
End If
Return MyBase.ProcessCmdKey(msg, keyData)
End Function
'
'This routine handles Cell Editing
Protected Overrides Function ProcessDialogKey(ByVal keyData As System.Windows.Forms.Keys) As Boolean
If keyData = Keys.Return Then
keyData = Keys.Tab
End If
Return MyBase.ProcessDialogKey(keyData)
End Function
But a situation has come up where I want to place a Button cell type into the row. I don't want to process ENTER > TAB for that cell type. I would prefer ENTER to work as ENTER.
I cannot find any example code to show me how to determine the CELLTYPE of the cell where I'm processing the keystroke.
Any help appreciated.
I have form1 that whenever I press F1..
Protected Overrides Function ProcessCmdKey(ByRef msg As Message, ByVal keyData As Keys) As Boolean
If keyData = Keys.F1 Then
Form2.Show()
Return True
End If
Return MyBase.ProcessCmdKey(msg, keyData)
End Function
form2 shows..
what I wanted is when form2 is up, and I press F1 again, it closes.
any idea? thanks
Just write the same code you wrote but in Form2 and say form2.close()
If keyData = Keys.F1 Then
Form2.Close()
Return True
End If