Backcolor of Main menu

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Using VS VB.NET Is is possible to control the color menus? Including the main
menu bar?

THanks in advance
 
Set the OwnerDraw property to true and add event handlers for the DrawItem
and MeasureItem events of your menuitems. The following code assumes you
have a main menu called menuItem1 containing a number of submenus:

private void menuItem2_DrawItem(object sender,
System.Windows.Forms.DrawItemEventArgs e)
{
string menuCaption = this.menuItem1.MenuItems[e.Index].Text;
Brush bgBrush = ((e.State & DrawItemState.Selected) > 0) ?
Brushes.Gray : Brushes.Yellow;
Brush captionBrush = System.Drawing.Brushes.Blue;
Font captionFont = new Font(FontFamily.GenericSerif, 14,
FontStyle.Underline, GraphicsUnit.Pixel);
e.Graphics.FillRectangle(bgBrush, new Rectangle(e.Bounds.X,
e.Bounds.Y, e.Bounds.Width, e.Bounds.Height));
e.Graphics.DrawString(menuCaption, captionFont, captionBrush,
e.Bounds.X, e.Bounds.Y);
}

private void menuItem2_MeasureItem(object sender,
System.Windows.Forms.MeasureItemEventArgs e)
{
string menuCaption = this.menuItem1.MenuItems[e.Index].Text;
Font captionFont = new Font(FontFamily.GenericSerif, 14,
FontStyle.Underline, GraphicsUnit.Pixel);
SizeF mySizeF = e.Graphics.MeasureString(menuCaption,
captionFont);
e.ItemHeight = Convert.ToInt32(mySizeF.Height);
e.ItemWidth = Convert.ToInt32(mySizeF.Width);
}

HTH, Jakob.
 
Back
Top