Shortcut key

  • Thread starter Thread starter John J. Hughes II
  • Start date Start date
J

John J. Hughes II

I have an MDI application with a menu, toolbard, datagrid, property grid,
and some text controls and drop down lists on a form. There are two items
on the menu (refresh F5) and (update F9). The F5 works fine but the F9 does
does not. Clicking the update menu button works fine and the show short cut
is equal true in problems.

Is there anything else that uses the F9 key, as far as I can tell I am not
using it.

Regards,
John
 
Hi John,

I tested the F9 shortcut using a simple MDI application, it works fine as
F5.
I suspect this issue related to the Cmd key processing in certian controls,
because the focused control will get the win32 key messages, and it depends
on their implementation to determine if the input is a command key and if
they should ask their parent to process it.

Have you tried setting focus onto some other control and test F9 key?
You may add a new Form with a button on it, when you do test , first set
the focus to the button then press F9 key to see if it will execute the
corresponding menu item handler.
If this works fine, you may need to check the controls on your original
form (or toolb bar etc.. ).

Feel free to let me know, if you have any updates or meet any problem when
troubleshooting this issue.

Good Luck!

Best regards,

Ying-Shen Yu [MSFT]
Microsoft Community Support
Get Secure! - www.microsoft.com/security

This posting is provided "AS IS" with no warranties and confers no rights.
This mail should not be replied directly, please remove the word "online"
before sending mail.
 
I don't handle the processing of the keys I just added it to the menu as a
shortcut. It works on other MDI forms, just not this one. If I change it
to F7 it works fine. The problem is all my other forms use F9 so I sort of
have to keep it.

I assume something is stealing it and the only thing on this form and not
the others is the tool bar... hum?

Regards,
John
 
Ok but I don't think I understand.

This is what the "Windows Form Designer" code looks like and below that is
event handler for the menu item. The F9 shortcut is stored in the resource
file. If I click the menu item it works fine. If I put a break point on
the SaveRecord function and press F9 the code is never reached.

//
// menuUpdate
//
this.menuUpdate.Enabled =
((bool)(resources.GetObject("menuUpdate.Enabled")));
this.menuUpdate.Index = 0;
this.menuUpdate.Shortcut =
((System.Windows.Forms.Shortcut)(resources.GetObject("menuUpdate.Shortcut"))
);
this.menuUpdate.ShowShortcut =
((bool)(resources.GetObject("menuUpdate.ShowShortcut")));
this.menuUpdate.Text = resources.GetString("menuUpdate.Text");
this.menuUpdate.Visible =
((bool)(resources.GetObject("menuUpdate.Visible")));
this.menuUpdate.Click += new System.EventHandler(this.menuUpdate_Click);

/// This is the event handler for the menu item.

private void menuUpdate_Click(object sender, System.EventArgs e)
{
this.SaveRecord();
}
 
Hi John,

You may try overridding the Form.ProcessCmdKey method and set a breakpoint
in it, if everything works fine, this breakpoint will be reached when you
press F9 key. Here is a sample of the call stack when the menu item client
event finally fires.
WindowsApplication32.exe!WindowsApplication32.Form1.menuItem2_Click(System.
Object sender = {System.Windows.Forms.MenuItem}, System.EventArgs e =
{System.EventArgs})
system.windows.forms.dll!System.Windows.Forms.MenuItem.OnClick(System.EventA
rgs e = {System.EventArgs}) + 0x8f bytes
system.windows.forms.dll!System.Windows.Forms.MenuItem.ShortcutClick() +
0x92 bytes
system.windows.forms.dll!System.Windows.Forms.Menu.ProcessCmdKey(System.Wind
ows.Forms.Message msg = {System.Windows.Forms.Message},
system.windows.forms.dll!System.Windows.Forms.Form.ProcessCmdKey(System.Wind
ows.Forms.Message msg = {System.Windows.Forms.Message},
system.windows.forms.dll!System.Windows.Forms.Control.ProcessCmdKey(System.W
indows.Forms.Message msg = {System.Windows.Forms.Message},
system.windows.forms.dll!System.Windows.Forms.Control.ProcessCmdKey(System.W
indows.Forms.Message msg = {System.Windows.Forms.Message},
system.windows.forms.dll!System.Windows.Forms.Form.ProcessCmdKey(System.Wind
ows.Forms.Message msg = {System.Windows.Forms.Message},
system.windows.forms.dll!System.Windows.Forms.Control.ProcessCmdKey(System.W
indows.Forms.Message msg = {System.Windows.Forms.Message},
system.windows.forms.dll!System.Windows.Forms.Control.PreProcessMessage(Syst
em.Windows.Forms.Message msg = {System.Windows.Forms.Message})
....
Hope it helps!

Best regards,

Ying-Shen Yu [MSFT]
Microsoft Community Support
Get Secure! - www.microsoft.com/security

This posting is provided "AS IS" with no warranties and confers no rights.
This mail should not be replied directly, please remove the word "online"
before sending mail.
 
Thanks for the suggestion.

If I do the following I can get my records to update but it does not explain
what is stealing the F9 key. I still think it's the toolbar since the F9
works on all my other windows but not this one and the only real change is
the toolbar. The problem with that logic is if I add a toolbar to another
window the F9 still works. I can only assume I have done something to mess
it up but I have no clue what. Someday when I have time maybe I will make a
copy and start removing items until it works.

protected override bool ProcessCmdKey(ref Message msg, Keys keyData)
{
if(keyData == Keys.F9)
{
this.SaveRecord();
return true;
}
return base.ProcessCmdKey (ref msg, keyData);
}

My call stack when I get to the first line above is as follows if that tells
you anything.

ramsdir.dll!RAMSDir.frmPayphones.ProcessCmdKey(System.Windows.Forms.Message
msg = {System.Windows.Forms.Message}, System.Windows.Forms.Keys keyData =
F9) Line 2734 C#
system.windows.forms.dll!System.Windows.Forms.Control.ProcessCmdKey(System.W
indows.Forms.Message msg = {System.Windows.Forms.Message},
System.Windows.Forms.Keys keyData = F9) + 0x72 bytes
system.windows.forms.dll!System.Windows.Forms.Control.PreProcessMessage(Syst
em.Windows.Forms.Message msg = {System.Windows.Forms.Message}) + 0x96 bytes
system.windows.forms.dll!ThreadContext.System.Windows.Forms.UnsafeNativeMeth
ods+IMsoComponent.FPreTranslateMessage(System.Windows.Forms.NativeMethods.MS
G msg = {System.Windows.Forms.NativeMethods.MSG}) + 0x1cd bytes
system.windows.forms.dll!System.Windows.Forms.Application.ComponentManager.S
ystem.Windows.Forms.UnsafeNativeMethods+IMsoComponentManager.FPushMessageLoo
p(int dwComponentID = 0x1, int reason = 0xffffffff, int pvLoopData = 0x0) +
0x326 bytes
system.windows.forms.dll!ThreadContext.RunMessageLoopInner(int reason =
0xffffffff, System.Windows.Forms.ApplicationContext context =
{System.Windows.Forms.ApplicationContext}) + 0x1f3 bytes
system.windows.forms.dll!ThreadContext.RunMessageLoop(int reason =
0xffffffff, System.Windows.Forms.ApplicationContext context =
{System.Windows.Forms.ApplicationContext}) + 0x50 bytes
system.windows.forms.dll!System.Windows.Forms.Application.Run(System.Windows
..Forms.Form mainForm = {RAMS.frmRAMSMain}) + 0x34 bytes
RAMS.exe!RAMS.frmRAMSMain.Main() Line 151 C#

Regards,
John
 
Hi John,
if the problem only occured when the focus is on the ToolBar, probably the
ProcessCmdKey does not call parent's ProcessCmdKey when processing the F9
key. Are you using the Toolbar class in .NET Framwork SDK? Have you made
any customizations on it?
If this issue could be reproduced in a small application, you may send it
to my mailbox to let me take a look at it.

Thanks!

Best regards,

Ying-Shen Yu [MSFT]
Microsoft Community Support
Get Secure! - www.microsoft.com/security

This posting is provided "AS IS" with no warranties and confers no rights.
This mail should not be replied directly, please remove the word "online"
before sending mail.
 
It's a standard toolbar, no changes on my part.

Yea if I can get it work on a smaller application I will forward it.

Regards,
John
 
Back
Top