Click here to Skip to main content
13,140,231 members (47,913 online)
Rate this:
Please Sign up or sign in to vote.
See more:
How to change the back color of menu item on mouse leave ?
Any help in this regard ?
Posted 9-Sep-12 18:43pm

1 solution

Rate this: bad
Please Sign up or sign in to vote.

Solution 1


just subscribe to the MouseLeave event for the desired MenuItem and use this code as an example:
private void toolStripMenuItem1_MouseLeave(object sender, EventArgs e)
   ((ToolStripMenuItem)sender).BackColor = Color.Red;
Itz.Irshad 10-Sep-12 1:26am
Your answer is much accurate. But, I've something more to do. Actually, On sub-menu Item I have created a rectangle with x as a representation of close button. So, I've changed that rectangle back color to blue (highlight) on mouseover. Now, I need to change that color to default(previous). How can I do this? Code is attached below:
protected override void OnPaint(PaintEventArgs e)

SolidBrush brush;
Rectangle r = new Rectangle(this.Bounds.Width - 20, 2, 16, 17);

// If click on Del(Close Icon)
if (bOnDel)
brush = new SolidBrush(Color.LightBlue);
e.Graphics.FillRectangle(brush, r);
brush.Color = Color.Blue;
e.Graphics.DrawRectangle(new Pen(brush, 1), r);
// If didn't click on Del(Close Icone)
if (!bOnDel)

brush = new SolidBrush(Color.FromKnownColor(KnownColor.Transparent));
e.Graphics.FillRectangle(brush, r);
brush.Color = Color.FromKnownColor(KnownColor.Transparent);
e.Graphics.DrawRectangle(new Pen(brush, 1), r);

//Code for Drawing Cross Lines

brush = new SolidBrush(Color.Gray);
Rectangle rCross = new Rectangle(this.Bounds.Width - 15, 8, 6, 6);
e.Graphics.DrawLine(new Pen(brush, 2), new Point(rCross.Right, rCross.Top), new Point(rCross.Left, rCross.Bottom));
e.Graphics.DrawLine(new Pen(brush, 2), new Point(rCross.Left, rCross.Top), new Point(rCross.Right, rCross.Bottom));
JF2015 10-Sep-12 1:32am
the default color is: System.Drawing.SystemColors.Control
Itz.Irshad 10-Sep-12 1:41am
Your're right. But, when we do mouseover the menu item its color changed from default to light yellow or mic of (Yellow and Some other color) in default behavior of menu tool strip. So, How I can update my run-time drawn rectangle color to that color on leaving mouse from menu item ?

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
Top Experts
Last 24hrsThis month

Advertise | Privacy |
Web02 | 2.8.170915.1 | Last Updated 10 Sep 2012
Copyright © CodeProject, 1999-2017
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100