473,320 Members | 2,098 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,320 software developers and data experts.

MenuItem Drawing text with Formatted Shortcuts

Lex
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 in col 2. This
is what a standard menu with shortcuts looks like.

Anyone have any ideas on how to accompilsh this?
Best Regards
Jul 21 '05 #1
5 1885
When I do this I right-align the shorcut. Take a look at Office and VS.net menus and you'll see that that's what MS are doing too. The problem with left aligning in seperate columns is that you must know the longest menuitems text and the longest shortcut text in a popupmenu before your OnMeasureItem method runs. This also results in longer menus and wasted space as demonstrated below.

Left aligned text + right aligned shortcut
----------------------------------------------
Short Text Ctrl+Shift+Ins |
And a much longer string in a menu item Ins |
----------------------------------------------

Left aligned text + left aligned shortcut in second column
---------------------------------------------------------
Short Text Ctrl+Shift+Ins |
And a much longer string in a menu item Ins |
---------------------------------------------------------

p.s. I sent this in html format with a fixed-width font for display purposes.

--
Mick Doherty
http://homepage.ntlworld.com/mdaudi1...ate/menus.html
---
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 #2
Hi,

I thought this was the default for two columns. In the following example, no
matter what you put in the first column of each menuitem, the second column
lines up.

// Add File Menu
MenuItem File = mainMenu.MenuItems.Add("&File");
File.MenuItems.Add( new MenuItem( "&New",
new EventHandler(
this.FileNew_Clicked ),
Shortcut.CtrlN ));
File.MenuItems.Add( new MenuItem( "&Open",
new EventHandler(
this.FileOpen_Clicked ),
Shortcut.CtrlO ));
File.MenuItems.Add("-"); // Gives us a seperator
File.MenuItems.Add( new MenuItem( "E&xit",
new EventHandler(
this.FileExit_Clicked ),
Shortcut.CtrlX ));

I have a sample which shows this in action here.
http://www.publicjoe.f9.co.uk/csharp\csharp14.html

Look at code for menudemo3.cs near the bottom of the page.

Hope this helps

Publicjoe
C# Tutorial at http://www.publicjoe.f9.co.uk/csharp/tut.html
C# Snippets at http://www.publicjoe.f9.co.uk/csharp/snip/snippets.html
C# Ebook at http://www.publicjoe.f9.co.uk/csharp/samples/ebook.html

"Lex" <de**@homerlex.mailshell.com> wrote in message
news:c5*************************@posting.google.co m...
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 in col 2. This
is what a standard menu with shortcuts looks like.

Anyone have any ideas on how to accompilsh this?
Best Regards

Jul 21 '05 #3
Lex
Thanx again Mick. You seem to be the expert on custom menus :-)

Have you every had to deal with the following?

I have a menu that has a mixture of OwnerDrawn and non-OwnerDrawn
items. I want my OwnerDrawn items to indent the exact amount needed
to match the non_OwnerDrawn indent. I can eyeball it and use
e.Bounds.Left + x but is there a better way to match the indent?

Same issue with getting a matching height in the MeasureItem event.

Any suggestions (other than making all the items owner drawn, which is
an option but I'd rather avoid that for some coding reasons that are
not important for this discussion).

Regards

"Mick Doherty" <EX***********@AND.REMOVE.SQUAREBRACKETS.[mdaudi100#ntlworld.com]> wrote in message news:<uO**************@TK2MSFTNGP09.phx.gbl>...
When I do this I right-align the shorcut. Take a look at Office and
VS.net menus and you'll see that that's what MS are doing too. The
problem with left aligning in seperate columns is that you must know the
longest menuitems text and the longest shortcut text in a popupmenu
before your OnMeasureItem method runs. This also results in longer menus
and wasted space as demonstrated below.

Left aligned text + right aligned shortcut
----------------------------------------------
Short Text Ctrl+Shift+Ins |
And a much longer string in a menu item Ins |
----------------------------------------------

Left aligned text + left aligned shortcut in second column
---------------------------------------------------------
Short Text Ctrl+Shift+Ins |
And a much longer string in a menu item Ins |
---------------------------------------------------------

p.s. I sent this in html format with a fixed-width font for display
purposes.

--
Mick Doherty
http://homepage.ntlworld.com/mdaudi1...ate/menus.html
---
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 #4
Height:
\\\
SystemInformation.MenuHeight
///
Text Offset:
\\\
SystemInformation.MenuCheckSize.Width + _
SystemInformation.FixedFrameBorderSize.Width
///

If you're going to mix and match then you'll have to use two columns for
menuitemtext since that's the default for non-ownerdraw menuitems. As
explained in the last message you will need to know the longest shortcut
text when calling measureitem on the menuitem with the longest caption.
--
Mick Doherty
http://homepage.ntlworld.com/mdaudi1...nate/home.html
"Lex" <de**@homerlex.mailshell.com> wrote in message
news:c5************************@posting.google.com ...
Thanx again Mick. You seem to be the expert on custom menus :-)

Have you every had to deal with the following?

I have a menu that has a mixture of OwnerDrawn and non-OwnerDrawn
items. I want my OwnerDrawn items to indent the exact amount needed
to match the non_OwnerDrawn indent. I can eyeball it and use
e.Bounds.Left + x but is there a better way to match the indent?

Same issue with getting a matching height in the MeasureItem event.

Any suggestions (other than making all the items owner drawn, which is
an option but I'd rather avoid that for some coding reasons that are
not important for this discussion).

Regards

"Mick Doherty"

<EX***********@AND.REMOVE.SQUAREBRACKETS.[mdaudi100#ntlworld.com]> wrote in
message news:<uO**************@TK2MSFTNGP09.phx.gbl>...
When I do this I right-align the shorcut. Take a look at Office and
VS.net menus and you'll see that that's what MS are doing too. The
problem with left aligning in seperate columns is that you must know the
longest menuitems text and the longest shortcut text in a popupmenu
before your OnMeasureItem method runs. This also results in longer menus
and wasted space as demonstrated below.

Left aligned text + right aligned shortcut
----------------------------------------------
Short Text Ctrl+Shift+Ins |
And a much longer string in a menu item Ins |
----------------------------------------------

Left aligned text + left aligned shortcut in second column
---------------------------------------------------------
Short Text Ctrl+Shift+Ins |
And a much longer string in a menu item Ins |
---------------------------------------------------------

p.s. I sent this in html format with a fixed-width font for display
purposes.

--
Mick Doherty
http://homepage.ntlworld.com/mdaudi1...ate/menus.html
---
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
--

---
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 #5
http://www.vbdotnetheaven.com/

Lex wrote:
Thanx again Mick. You seem to be the expert on custom menus :-)

Have you every had to deal with the following?

I have a menu that has a mixture of OwnerDrawn and non-OwnerDrawn
items. I want my OwnerDrawn items to indent the exact amount needed
to match the non_OwnerDrawn indent. I can eyeball it and use
e.Bounds.Left + x but is there a better way to match the indent?

Same issue with getting a matching height in the MeasureItem event.

Any suggestions (other than making all the items owner drawn, which is
an option but I'd rather avoid that for some coding reasons that are
not important for this discussion).

Regards

"Mick Doherty" <EX***********@AND.REMOVE.SQUAREBRACKETS.[mdaudi100#ntlworld.com]> wrote in message news:<uO**************@TK2MSFTNGP09.phx.gbl>...
When I do this I right-align the shorcut. Take a look at Office and
VS.net menus and you'll see that that's what MS are doing too. The
problem with left aligning in seperate columns is that you must know the
longest menuitems text and the longest shortcut text in a popupmenu
before your OnMeasureItem method runs. This also results in longer menus
and wasted space as demonstrated below.

Left aligned text + right aligned shortcut
----------------------------------------------
Short Text Ctrl+Shift+Ins |
And a much longer string in a menu item Ins |
----------------------------------------------

Left aligned text + left aligned shortcut in second column
---------------------------------------------------------
Short Text Ctrl+Shift+Ins |
And a much longer string in a menu item Ins |
---------------------------------------------------------

p.s. I sent this in html format with a fixed-width font for display
purposes.

--
Mick Doherty
http://homepage.ntlworld.com/mdaudi1...ate/menus.html
---
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

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

Similar topics

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...
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...
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...
6
by: Eric Sabine | last post by:
Basically, the following code creates a menuItem array and tries to use it twice. In the following piece of code, only the line that appears second gets used. The first becomes ignored presumably...
2
by: polocar | last post by:
Hi, I'm writing a program using Visual C# 2005 Professional Edition, and I was trying to assign multiple MainMenu objects (one by one, of course) to the same Form (let's suppose 2 MainMenu...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 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 former...

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.