I am developing a windows forms application using VS.NET in C#. I am using
the MDI style. I have a main menu defined with several layers of menu items.
I know that I can change the appearance of all menus by changing the Menu
property within the advanced appearance of the system display properties.
But I only want to change the font size and style of the menu within my
application.

How can I change the font of the menu only for my application?

Thanks,
Dave

RE: How to change the font of the main menu in application window? by v-jetan

v-jetan
Tue Sep 28 21:25:26 CDT 2004

Hi Dave,

Based on my understanding, you want to change the font of the Winform
application menu.

Net did not have build-in support for setting the menu font. But we may
owner-draw the menu, and draw the text in specific font. For more
information, please refer to below article:
"Owner Draw Menus in C#"
http://www.c-sharpcorner.com/Code/2002/April/OwnerDrawMenusSK.asp

=============================================
Please apply my suggestion above and let me know if it helps resolve your
problem.

Thank you for your patience and cooperation. If you have any questions or
concerns, please feel free to post it in the group. I am standing by to be
of assistance.

Best regards,
Jeffrey Tan
Microsoft Online Partner Support
Get Secure! - www.microsoft.com/security
This posting is provided "as is" with no warranties and confers no rights.


RE: How to change the font of the main menu in application window? by babel

babel
Wed Sep 29 19:23:04 CDT 2004

Jeffrey,

The link you sent helped out some. However, the example does not explain
how to get similar behavior as the standard MenuItem class. For example, I
would like my menu items (MyMenuItem) to support underlining the accelerator
character. The example just underlines the whole menu item text. Basically,
I want my application menu items to behave and appear just like default menu
items except I want to specify the font (family,size, style).

I believe I know how to handle all of the DrawItemEventArgs members except
the State member.

How do I handle all of the different DrawItemEventArgs.State values with
appropriate forecolor, backcolor and underlining?

Thanks,
Dave

""Jeffrey Tan[MSFT]"" wrote:

> Hi Dave,
>
> Based on my understanding, you want to change the font of the Winform
> application menu.
>
> .Net did not have build-in support for setting the menu font. But we may
> owner-draw the menu, and draw the text in specific font. For more
> information, please refer to below article:
> "Owner Draw Menus in C#"
> http://www.c-sharpcorner.com/Code/2002/April/OwnerDrawMenusSK.asp
>
> =============================================
> Please apply my suggestion above and let me know if it helps resolve your
> problem.
>
> Thank you for your patience and cooperation. If you have any questions or
> concerns, please feel free to post it in the group. I am standing by to be
> of assistance.
>
> Best regards,
> Jeffrey Tan
> Microsoft Online Partner Support
> Get Secure! - www.microsoft.com/security
> This posting is provided "as is" with no warranties and confers no rights.
>
>

Re: How to change the font of the main menu in application window? by Mick

Mick
Thu Sep 30 01:08:59 CDT 2004

You'll find an Office style OwnerDraw menu example on my site, which shows
how to do this.
http://dotnetrix.co.uk/menus.html

--
Mick Doherty
http://dotnetrix.co.uk/nothing.html


"Dave Leach" <babel@agilent.com> wrote in message
news:C7062C09-5B82-45DC-B28A-A777A23DFFE4@microsoft.com...
> Jeffrey,
>
> The link you sent helped out some. However, the example does not explain
> how to get similar behavior as the standard MenuItem class. For example,
> I
> would like my menu items (MyMenuItem) to support underlining the
> accelerator
> character. The example just underlines the whole menu item text.
> Basically,
> I want my application menu items to behave and appear just like default
> menu
> items except I want to specify the font (family,size, style).
>
> I believe I know how to handle all of the DrawItemEventArgs members except
> the State member.
>
> How do I handle all of the different DrawItemEventArgs.State values with
> appropriate forecolor, backcolor and underlining?
>
> Thanks,
> Dave
>
> ""Jeffrey Tan[MSFT]"" wrote:
>
>> Hi Dave,
>>
>> Based on my understanding, you want to change the font of the Winform
>> application menu.
>>
>> .Net did not have build-in support for setting the menu font. But we may
>> owner-draw the menu, and draw the text in specific font. For more
>> information, please refer to below article:
>> "Owner Draw Menus in C#"
>> http://www.c-sharpcorner.com/Code/2002/April/OwnerDrawMenusSK.asp
>>
>> =============================================
>> Please apply my suggestion above and let me know if it helps resolve your
>> problem.
>>
>> Thank you for your patience and cooperation. If you have any questions or
>> concerns, please feel free to post it in the group. I am standing by to
>> be
>> of assistance.
>>
>> Best regards,
>> Jeffrey Tan
>> Microsoft Online Partner Support
>> Get Secure! - www.microsoft.com/security
>> This posting is provided "as is" with no warranties and confers no
>> rights.
>>
>>


---
Outgoing mail is certified Virus Free.
Checked by AVG anti-virus system (http://www.grisoft.com).
Version: 6.0.742 / Virus Database: 495 - Release Date: 19/08/2004



RE: How to change the font of the main menu in application window? by v-jetan

v-jetan
Thu Sep 30 04:47:08 CDT 2004

Hi Dave,

Thanks for your feedback.

I think you want to draw your own menuitem text, but with the accelerator
character a underline to clew the user that he can use "alt"+ "accelerator
character" to simulate the click operation. Yes?

I will spend some time on it, and reply to you some time later. Thanks for
your understanding.

Best regards,
Jeffrey Tan
Microsoft Online Partner Support
Get Secure! - www.microsoft.com/security
This posting is provided "as is" with no warranties and confers no rights.


RE: How to change the font of the main menu in application window? by babel

babel
Thu Sep 30 10:39:06 CDT 2004

Jeffrey,

Yes, I want the same accelerator behavior as the MenuItem class. I really
just
need to be able to control the Font.

Thanks,
Dave

""Jeffrey Tan[MSFT]"" wrote:

> Hi Dave,
>
> Thanks for your feedback.
>
> I think you want to draw your own menuitem text, but with the accelerator
> character a underline to clew the user that he can use "alt"+ "accelerator
> character" to simulate the click operation. Yes?
>
> I will spend some time on it, and reply to you some time later. Thanks for
> your understanding.
>
> Best regards,
> Jeffrey Tan
> Microsoft Online Partner Support
> Get Secure! - www.microsoft.com/security
> This posting is provided "as is" with no warranties and confers no rights.
>
>

RE: How to change the font of the main menu in application window? by v-jetan

v-jetan
Thu Sep 30 21:34:26 CDT 2004

Hi Dave,

Thanks for your waiting.

Yes, after some research, we may use StringFormat to specify its
HotkeyPrefix property to System.Drawing.Text.HotkeyPrefix.Show, then place
a "&" infront of accelerator character, then draw this text out in specific
font, you will get what you want, sample code like this:

private void menuItem1_DrawItem(object sender,
System.Windows.Forms.DrawItemEventArgs e)
{
string myCaption="&Main Menu";

Brush myBrush = System.Drawing.Brushes.Black;
Font myFont = new Font(FontFamily.GenericSerif, 14, FontStyle.Underline,
GraphicsUnit.Pixel);

Console.WriteLine(e.State.ToString());
myFont = new Font(FontFamily.GenericSerif, 14, FontStyle.Regular,
GraphicsUnit.Pixel);
StringFormat sf = new StringFormat();
sf.HotkeyPrefix = System.Drawing.Text.HotkeyPrefix.Show;

e.Graphics.DrawString(myCaption, myFont, myBrush, e.Bounds.X, e.Bounds.Y,
sf);
}

private void menuItem1_MeasureItem(object sender,
System.Windows.Forms.MeasureItemEventArgs e)
{
string myCaption="&Main Menu";

Font myFont = new Font(FontFamily.GenericSerif, 14, FontStyle.Underline,
GraphicsUnit.Pixel);
Size mySize = e.Graphics.MeasureString(myCaption, myFont).ToSize();

e.ItemHeight=mySize.Height;
e.ItemWidth=mySize.Width;
}
===================================================
Thank you for your patience and cooperation. If you have any questions or
concerns, please feel free to post it in the group. I am standing by to be
of assistance.

Best regards,
Jeffrey Tan
Microsoft Online Partner Support
Get Secure! - www.microsoft.com/security
This posting is provided "as is" with no warranties and confers no rights.


Re: How to change the font of the main menu in application window? by Mick

Mick
Fri Oct 01 01:01:34 CDT 2004

To get the same behaviour as windows menu's, you would check whether the
mnemonic underline is visible. The DrawItemState Enumeration has a
NoAccelerator flag which we can use to check for whether the underscore
should be shown.

\\\
if (System.Convert.ToBoolean(e.State & DrawItemState.NoAccelerator))
sf.HotkeyPrefix = System.Drawing.Text.HotkeyPrefix.Hide;
else
sf.HotkeyPrefix = System.Drawing.Text.HotkeyPrefix.Show;
///

--
Mick Doherty
http://dotnetrix.co.uk/nothing.html


""Jeffrey Tan[MSFT]"" <v-jetan@online.microsoft.com> wrote in message
news:joTit81pEHA.752@cpmsftngxa06.phx.gbl...
> Hi Dave,
>
> Thanks for your waiting.
>
> Yes, after some research, we may use StringFormat to specify its
> HotkeyPrefix property to System.Drawing.Text.HotkeyPrefix.Show, then place
> a "&" infront of accelerator character, then draw this text out in
> specific
> font, you will get what you want, sample code like this:
>
> private void menuItem1_DrawItem(object sender,
> System.Windows.Forms.DrawItemEventArgs e)
> {
> string myCaption="&Main Menu";
>
> Brush myBrush = System.Drawing.Brushes.Black;
> Font myFont = new Font(FontFamily.GenericSerif, 14, FontStyle.Underline,
> GraphicsUnit.Pixel);
>
> Console.WriteLine(e.State.ToString());
> myFont = new Font(FontFamily.GenericSerif, 14, FontStyle.Regular,
> GraphicsUnit.Pixel);
> StringFormat sf = new StringFormat();
> sf.HotkeyPrefix = System.Drawing.Text.HotkeyPrefix.Show;
>
> e.Graphics.DrawString(myCaption, myFont, myBrush, e.Bounds.X, e.Bounds.Y,
> sf);
> }
>
> private void menuItem1_MeasureItem(object sender,
> System.Windows.Forms.MeasureItemEventArgs e)
> {
> string myCaption="&Main Menu";
>
> Font myFont = new Font(FontFamily.GenericSerif, 14, FontStyle.Underline,
> GraphicsUnit.Pixel);
> Size mySize = e.Graphics.MeasureString(myCaption, myFont).ToSize();
>
> e.ItemHeight=mySize.Height;
> e.ItemWidth=mySize.Width;
> }
> ===================================================
> Thank you for your patience and cooperation. If you have any questions or
> concerns, please feel free to post it in the group. I am standing by to be
> of assistance.
>
> Best regards,
> Jeffrey Tan
> Microsoft Online Partner Support
> Get Secure! - www.microsoft.com/security
> This posting is provided "as is" with no warranties and confers no rights.
>


---
Outgoing mail is certified Virus Free.
Checked by AVG anti-virus system (http://www.grisoft.com).
Version: 6.0.742 / Virus Database: 495 - Release Date: 19/08/2004



Re: How to change the font of the main menu in application window? by v-jetan

v-jetan
Fri Oct 01 02:06:41 CDT 2004

Hi Mick,

Oh, yes, you are correct. This is because the default setting in Control
Panel -> Display Properties -> Appearance -> Effects -> "Hide underlined
letter for keyboard navigation" is checked, so the underscore will be
displayed only when we pressed "Alt"(only when you pressed "Alt" key, the
DrawItemEventArgs.State will not have DrawItemStates.NoAccelerator flag).

So, we should use DrawItemEventArgs.State to get if windows wanted the
underscore through NoAccelerator flag, if needed, just paint with
HotkeyPrefix.Show.

Best regards,
Jeffrey Tan
Microsoft Online Partner Support
Get Secure! - www.microsoft.com/security
This posting is provided "as is" with no warranties and confers no rights.


Re: How to change the font of the main menu in application window? by babel

babel
Fri Oct 01 14:39:07 CDT 2004

Jeffrey and Mark,

I really appreciate the help you have provided. I have my MenuItem subclass
working just great now. It now accounts for State conditions I care about and
even handles the case where a menu item is used as a separator.

Mark, thanks for the link. The code samples there really helped a lot.

Thanks again,
Dave

""Jeffrey Tan[MSFT]"" wrote:

> Hi Mick,
>
> Oh, yes, you are correct. This is because the default setting in Control
> Panel -> Display Properties -> Appearance -> Effects -> "Hide underlined
> letter for keyboard navigation" is checked, so the underscore will be
> displayed only when we pressed "Alt"(only when you pressed "Alt" key, the
> DrawItemEventArgs.State will not have DrawItemStates.NoAccelerator flag).
>
> So, we should use DrawItemEventArgs.State to get if windows wanted the
> underscore through NoAccelerator flag, if needed, just paint with
> HotkeyPrefix.Show.
>
> Best regards,
> Jeffrey Tan
> Microsoft Online Partner Support
> Get Secure! - www.microsoft.com/security
> This posting is provided "as is" with no warranties and confers no rights.
>
>

Re: How to change the font of the main menu in application window? by v-jetan

v-jetan
Sun Oct 03 22:35:23 CDT 2004

Hi Dave,

You are welcome!

Best regards,
Jeffrey Tan
Microsoft Online Partner Support
Get Secure! - www.microsoft.com/security
This posting is provided "as is" with no warranties and confers no rights.