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