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

MenuItem Drawing text with Formatted Shortcuts

P: n/a
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
Share this Question
Share on Google+
5 Replies


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

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

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

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

P: n/a
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 discussion thread is closed

Replies have been disabled for this discussion.