By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
424,657 Members | 1,045 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 424,657 IT Pros & Developers. It's quick & easy.

MenuItem needs a Custom Shortcut

P: n/a
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
Jul 21 '05 #1
Share this Question
Share on Google+
10 Replies


P: n/a
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

"Lex" <de**@homerlex.mailshell.com> wrote in message
news:c5*************************@posting.google.co m...
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

Jul 21 '05 #2

P: n/a
Lex
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
"Vijaye Raji" <no*************@hotmail.com> wrote in message news:<um**************@tk2msftngp13.phx.gbl>...
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

"Lex" <de**@homerlex.mailshell.com> wrote in message
news:c5*************************@posting.google.co m...
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

Jul 21 '05 #3

P: n/a
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

"Lex" <de**@homerlex.mailshell.com> wrote in message
news:c5*************************@posting.google.co m...
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
"Vijaye Raji" <no*************@hotmail.com> wrote in message
news:<um**************@tk2msftngp13.phx.gbl>...
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

"Lex" <de**@homerlex.mailshell.com> wrote in message
news:c5*************************@posting.google.co m...
>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

Jul 21 '05 #4

P: n/a
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
"Lex" wrote:
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

Jul 21 '05 #5

P: n/a
That works a treat. I'll have to remember that one.

--
Mick Doherty
http://homepage.ntlworld.com/mdaudi1...nate/home.html
"Kristian Sandven" <Kr*************@discussions.microsoft.com> wrote in
message news:FA**********************************@microsof t.com...
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

---
Outgoing mail is certified Virus Free.
Checked by AVG anti-virus system (http://www.grisoft.com).
Version: 6.0.701 / Virus Database: 458 - Release Date: 07/06/2004
Jul 21 '05 #6

P: n/a
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

"Kristian Sandven" wrote:
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
"Lex" wrote:
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

Jul 21 '05 #7

P: n/a
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

"HomerLex" wrote:
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

"Kristian Sandven" wrote:
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
"Lex" wrote:
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

Jul 21 '05 #8

P: n/a
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.

"HomerLex" wrote:
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

"Kristian Sandven" wrote:
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
"Lex" wrote:
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

Jul 21 '05 #9

P: n/a
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/mdaudi1...nate/home.html
"HomerLex" <Ho******@discussions.microsoft.com> wrote in message
news:F5**********************************@microsof t.com...
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

---
Outgoing mail is certified Virus Free.
Checked by AVG anti-virus system (http://www.grisoft.com).
Version: 6.0.701 / Virus Database: 458 - Release Date: 07/06/2004
Jul 21 '05 #10

P: n/a
lex
Ah! - Thanx, yeah I was still owner drawing. Works very nicely!.

Regards
"Mick Doherty"
<EX***********@AND.REMOVE.SQUAREBRACKETS.[mdaudi100#ntlworld.com]> wrote in
message news:u9****************@TK2MSFTNGP11.phx.gbl...
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/mdaudi1...nate/home.html
"HomerLex" <Ho******@discussions.microsoft.com> wrote in message
news:F5**********************************@microsof t.com...
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

---
Outgoing mail is certified Virus Free.
Checked by AVG anti-virus system (http://www.grisoft.com).
Version: 6.0.701 / Virus Database: 458 - Release Date: 07/06/2004

Jul 21 '05 #11

This discussion thread is closed

Replies have been disabled for this discussion.