|
Hi All, I am working on an application which has a Main menu at the top of the application and another small menu strip inside the application. My problem is that i have shortcut keys added for the main menu. But for some of the shortcut keys it opens the menustrip inside the application. Like for example if there a top menu item which starts with A and also the inside menu strip which starts with A then it opens up the bottom menu strip at some cases. And this should not happen as per requirement. So if any one of you know how to disable the menu shortcut please help.
Thank you so much for your help in advance. -------------kings--------------- Moved byHarry ZhuMSFTFriday, July 24, 2009 5:23 AMrelating to menustrip (From:Visual C# Language)
-
|
| jacobkingsly Thursday, July 23, 2009 7:03 AM |
Hello Kings,
Tried the following in a sample application:
1. Added amenu strip with a menu item "File" - Set ALT-F as the shortcut key for this 2. Added another menu strip to a child panel in the same form. 3. Added a menu item "File1" in the second menu strip - Set ALT-F as the shortcut for this also 4. when i pressed ALT-F it always opens the main menu strip and not the second menu strip.
So can you please provide more input on how you are facing this problem ?
SVK |
| S V Krishnan Thursday, July 23, 2009 11:27 AM |
Hi jacobkingsly, If you want to dynamically disable some shortcut key, you can set it like this. item1ToolStripMenuItem.ShortcutKeys = Keys.None; When you want to enable it again, set it like this. item1ToolStripMenuItem.ShortcutKeys = (Keys.Control | Keys.A); Anyway, It is better not to use the same shortcut key for more than one menu item. Sincerely, Kira Qian Please mark the replies as answers if they help and unmark if they don't. |
| Kira Qian Monday, July 27, 2009 3:05 AM |
The main problem here is the menu itself is dynamically generated one. I don't know in advance what will get populated in the menu. And also I am not setting any of the shortcut keys. So by default it is taking the first key as shortcut key. -------------kings-------------- |
| jacobkingsly Monday, July 27, 2009 9:18 AM |
Hi jacobkingsly, Sorry I think I have misunderstood your meaning. What you mean is when you expend the menu item and press some key, the subitem start with the letter you have pressed will be selected or clicked. This is a default action for all menus in Windows OS. When you expand the menu item in Windows Explorer, IE, etc. It always click the item whose label start with the key you pressed. Sincerely, Kira Qian Please mark the replies as answers if they help and unmark if they don't. |
| Kira Qian Monday, July 27, 2009 10:00 AM |
I have a main menu which starts with letter "A" and i have set that letter as the shortcut key. Inside the form i have some tabs inside one of which i have a small menu strip whose value i am recieving from the backend. When the focus is inside the tab i mean when i click on the tabor do something inside the taband i press Alt+A it should actually open the main menu. instead it is opening the menustrip in the form. -------------kings-------------- |
| jacobkingsly Tuesday, July 28, 2009 12:29 PM |
Hi jacobkingsly, What does "menustrip in the form" mean? Could you please show me the screen shot? Did you add "&" before "A" to build a shortcut for the main menu? So it can be shown when press Alt+A. Sincerely, Kira Qian Please mark the replies as answers if they help and unmark if they don't. |
| Kira Qian Wednesday, July 29, 2009 2:11 AM |
Well I have given & for the main menu buti didnt set anything for the menu inside the tab. -------------kings-------------- |
| jacobkingsly Friday, July 31, 2009 6:19 AM |
jacobkingsly,
Did you happen to find a solution to this problem? I have a similar problem in that I have a MenuStrip and a ToolStrip on a form. The ToolStrip contains a button with the shortcut key Alt+F and the MenuStrip contains no shortcut for that key. Yet if I press Alt+F, it is dropping down the Fax menu instead of firing the Click event for the ToolStrip button.
Thanks John |
| smithjohnt Friday, September 11, 2009 8:51 PM |
This may require a bit (or a lot, depending on your project) of work, but I think it's the safest way to get the degree of control you need. Set your form's KeyPreview property to true; then add a handler for the KeyPress event for the form itself. Thanks to KeyPreview, this handler will be invoked before the key-press is sent to any other control in the form. Hence, apply your exact logics in this handler, and cancel the event when needed to avoid further processing. For example, you could check the keyboard shortcuts for each item on your main menu: if you find a match, force a click on it (toggle de drop-down state of the menu, and invoke its Click handlers, if any) and cancel the event. Otherwise, the event will be sent as normal to the relevant control and will be processed. As I said, this is quite a bit of work, but will do the job. Hope this helps. Regards, Herenvardo |
| herenvardo Friday, September 11, 2009 10:14 PM |
Here's how I recreated the issue with a simple sample app:
- Create a new dummy Windows Forms project
- In the new form, add a MenuStrip control and add a File menu with an Exit submenu item with no shortcut/hotkeys defined
- Add a ToolStrip control with a button that contains the text &Forward. Change the DisplayStyle to Image and Text.
- Add a Click event for the button with a MessageBox statement.
- Run the app and hit Alt+F. The File menu is dropped down instead of the button's click event being fired.
If you change the menu item's text to AFile and re-run, hit Alt+F and you get the message box. I would be interested to hear from someone that encountered the same issue and how they resolved it. It seems like a fairly common layout of controls and seems like a fairly major bug in my opinion.
Thanks John |
| smithjohnt Monday, September 14, 2009 6:22 PM |