0
votes

Using Visual Studio 2012

Added an MDI Form to project which creates a bunch of default menu items and then added the following code for the File/Open menu item:

Public Class MDIParent1

    Private Sub OpenFile(ByVal sender As Object, ByVal e As EventArgs) Handles OpenToolStripMenuItem.Click, OpenToolStripButton.Click
        Dim frm As New Form1
        With frm
            .MdiParent = Me
            .Show()
        End With
    End Sub
End Class

In another form, Form1, set KeyPreview = True and put in this code:

Public Class Form1

     Private Sub Form1_KeyUp(sender As Object, e As KeyEventArgs) Handles Me.KeyUp
        If e.KeyCode = Keys.Enter Then
            MsgBox("enter pressed")
        End If
    End Sub
End Class

Now, if you launch the MDI form and click the File menu (or ALT+F) then scroll down using arrow keys to Open and hit Enter on the keyboard, it launches Form1 but fires KeyUp(). In my actual application this ends up launching another child form to Form1 and I need to suppress the Enter key from the MDI menu launch but can't figure out how to do that.

1

1 Answers

0
votes

Handle KeyPress or KeyDown instead of KeyUp.