473,386 Members | 1,819 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 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 1893
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: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
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: 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,...
0
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...

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.