MenuItem needs a Custom Shortcut

  • Thread starter Thread starter Lex
  • Start date Start date
L

Lex

I am writing a C# app that has a Menu. Some of the menu items will
have short cuts that do not exist in the Shortcut enum. I would like
the custom shortcuts to appear on the menu but as far as I can tell
there is no way to add a short cut that is not in the Shortcut enum.

I have my on keyboard hook so I am not worried about the custom
shortcut magically working. I just want it to appear nicely formated
on the menu.

Anyone have any suggestions for doing this?

Regards
 
Subclass a menu item and make it owner drawn. Then override OnDrawItem and
draw all the text yourself. That way, you can control where the text is
drawn and what is drawn.

-vJ
 
Thanks for the reply.

Is there any way to tell if the Accelerator key was hit so I know if I
need to draw an underline or simply ignore the "&" in the text for
items with a mnemonic?

Regards
 
I think there's a way you can set the accelerator key for a menu item so, it
works automatically.

I think it was called Mnemonic or something like that.

-vJ
 
Hi

Here's a real simple solution:
If you have menuitem Open and you for example want the shortcut Ctrl+Alt+F1 (which does not exist in the shortcut enum) to appear in your menuitem.
Just write the following in the Text property of the menuitem: Open\tCtrl+Alt+F1.

Note: You still have to handle the shortcut in your keyboard hook.

- Kristian Sandven
 
Thanx for the suggestion but I had tried this in the past and it didn't work for me. The Text shows up as OpenCtrl+Alt+F1.

I did not purse this option as I figured there would still be a problem knowing how many tabs to put in.

Lets say you have a short Menu Text like Open and and longer one like "Start Without Debugging". Obviously you'd need more tabs after "Open" to line up the shortcuts.

Regards
 
Hi

It works for me if i set the text in the menu editor or directly in code.
Example
MenuItem item.....
item.Text = "Open\tCtrl+Alt+F1";

It does not work if you set the Text Property of the menuitem in the propertygrid.
I have no problems with the alignment of the shortcut text.

Regards
 
Hi

The text must be set in the Menudesigner or in code. Setting the text in the propertygrid does not work.
Example:
MenuItem item...
item.Text = "Open\tCtrl+Alt+F1";

Also I have no problem with the alignment of the shortcut text in the menuitems. I have a mix of the approach above and standard Shortcut enum in my menus and shortcut text is always nicely aligned to the right.

PS. I'm using Visual Studio .NET 7.1 and .NET framework 1.1.

Regards.
 
Works great here. Just one tab needed.
You did try this on a non ownerdraw item didn't you? It won't work on an
ownerdraw menuitem.

--
Mick Doherty
http://homepage.ntlworld.com/mdaudi100/alternate/home.html


HomerLex said:
Thanx for the suggestion but I had tried this in the past and it didn't
work for me. The Text shows up as OpenCtrl+Alt+F1.
I did not purse this option as I figured there would still be a problem
knowing how many tabs to put in.
Lets say you have a short Menu Text like Open and and longer one like
"Start Without Debugging". Obviously you'd need more tabs after "Open" to
line up the shortcuts.
 
Back
Top