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.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads

backcolor 2
Menu at runtime 1
Merging main menus 2
backcolor 5
Changing Form BackColor in VB 1
Change backcolor of the checkbox component 3
Switchboard Menu Labels 5
Restrict accessing menu for certain users 0

Back
Top