JamieB Posted January 10, 2006 Posted January 10, 2006 I need to write a menu control and was hoping to base it on ContextMenu, owner-drawn to conform with my GUI style. My problem is that the mnemonic keys do not work when OwnerDraw is true. In itself that wouldn't be too bad if I could capture key press events but I can't find a way to do that either whilst the menu is displayed. Does anybody know a way around this? Quote
Leaders snarfblam Posted January 10, 2006 Leaders Posted January 10, 2006 Mnemonics seem to work for me with owner drawn context menus. It might be worth mentioning that there is an overload for DrawString which takes a StringFormat object which allows you to render text with underlined mnemonics. MyStringFormat.HotkeyPrefix = System.Drawing.Text.HotkeyPrefix.Show; MyStringFormat.HotkeyPrefix = System.Drawing.Text.HotkeyPrefix.Show Quote [sIGPIC]e[/sIGPIC]
JamieB Posted January 11, 2006 Author Posted January 11, 2006 Thanks, I did that. The mnemonics are underlined and the debugger shows the Mnemonic properties are set, but pressing the corresponding keys on the keyboard has no effect. If I use the same code with a MainMenu it works ok. I've attached some sample code in case it helps.Form1.txt Quote
Leaders snarfblam Posted January 12, 2006 Leaders Posted January 12, 2006 Here is the difference. When I tried it, I had the control automatically display the context menu by setting the control's ContextMenu property to my context menu. In your code, you explicitly call the ContextMenu.Show method. This shouldn't make a difference, but appearently it does. If possible, set your context menu to be displayed automatically by setting it as a control's context menu (don't know if this is a 2.0 only feature or what). Quote [sIGPIC]e[/sIGPIC]
JamieB Posted January 12, 2006 Author Posted January 12, 2006 You are right - it does work when I set the Form's ContextMenu property. And I suspect that indeed it shouldn't make a difference. Hmm... I was planning to show menus in response to certain key presses in my app, which is required to run 'mouseless', so I need a bit of a rethink there. Anyway, many thanks for your help! Quote
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.