Click here to Skip to main content
16,021,041 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi all,

I created a menu in MDI with F1 shortcut and at the same time i am using F1 key in textbox key down event in some form.Issue is when i hit F1 in that form text box key down event is not raising where as it's raising menu item click event.How can i resolve this issue.

Help me out..
Posted
Comments
♥…ЯҠ…♥ 30-Apr-13 8:45am    
Have you written code behind for TextBox keydown for F1 key?
DileepkumarReddy 30-Apr-13 8:47am    
Yes !!! Ofcourse
Kschuler 30-Apr-13 9:05am    
Click the Improve question link and add your code to the question. We can't help you if we can't see what you are doing.

1 solution

Since the F1 shortcut has already been assigned to a menu item in the main MDI form, you cannot use it anymore in its MDI children form.

You can however do some simple settings change to make it work.

I assume you want the F1 do different action while the main MDI form is focused and another different action when the MDI children is focused. If that is so then you can do the following.

First at main MDI form, when opening the children form, remove the F1 shortcut key

VB
Private Sub TestToolStripMenuItem_Click(ByVal sender As Object, ByVal e As EventArgs) Handles TestToolStripMenuItem.Click
        TestToolStripMenuItem.ShortcutKeys = Keys.None
        Dim f As New Form2
        f.MdiParent = Me
        f.Show()
    End Sub


Then when that children form closes, just assign the shortcut key back

VB
Private Sub Form2_FormClosing(ByVal sender As Object, ByVal e As FormClosingEventArgs) Handles Me.FormClosing
       TryCast(Me.MdiParent, MDIForm).TestToolStripMenuItem.ShortcutKeys = Keys.F1
   End Sub

   Private Sub Form2_KeyDown(ByVal sender As Object, ByVal e As KeyEventArgs) Handles Me.KeyDown
       If e.KeyCode = Keys.F1 Then
           'Do stuff
       End If
   End Sub
 
Share this answer
 
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900