473,386 Members | 1,812 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

MenuItem needs a Custom Shortcut

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
10 2519
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
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
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
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
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
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
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
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
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
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

5
by: Lex | last post by:
As you may have seen in other posts I have a C# app that has custom shortcuts so I need to OwnerDraw my MenuItems. Thanx to vJ and Mick for the tips so far. I am almost there :-) My last (I...
10
by: Lex | last post by:
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...
0
by: Marcel | last post by:
Hi, the application I am writing has a MainMenu and a DataGrid (UltraGrid). Now I have to edit the text of each cell in this grid. So far so good. All works fine in editmode but if I press a...
6
by: Claus Holm | last post by:
I'm trying to enable a menuitem in the parent form from a mdichild. Rather than making the menuitems public, I'd go for a public method in the parent form to do the change, but when I call the...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.