473,695 Members | 2,626 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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 2568
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.goog le.com...
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******* *******@tk2msft ngp13.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.goog le.com...
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.goog le.com...
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******* *******@tk2msft ngp13.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.goog le.com...
>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.m icrosoft.com> wrote in
message news:FA******** *************** ***********@mic rosoft.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******@discu ssions.microsof t.com> wrote in message
news:F5******** *************** ***********@mic rosoft.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

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

5
1918
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 hope) issue is aligning the menu text and shortcut text properly. I need it to line up as if there are two columns - 1 for the menu text and one for the shortcut text. The menu text is left justified in col 1 and shortcur text is left justified...
10
1688
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 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...
0
2778
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 key which is also a shortcut it doesn´t work and the menuitem-clickevent will be performed.
6
6221
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 method from the mdichild, I get this error: C:\MyProjects\Visual Studio Projects\Tournament\Forms\frmLogin.cs(69): The name 'test' does not exist in the class or namespace 'Tournament.frmLogin' frmLogin is the mdichild.
0
8640
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9122
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
9001
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
8860
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
1
6496
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
4348
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4587
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
2280
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
1980
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.