Jump to content
Xtreme .Net Talk

Recommended Posts

Posted
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?
  • Leaders
Posted

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

[sIGPIC]e[/sIGPIC]
Posted

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

  • Leaders
Posted

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).

[sIGPIC]e[/sIGPIC]
Posted

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!

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...