WinForm应用程序中使用了菜单工具条。在检查菜单选项时,它会打开子菜单。当鼠标进入子菜单边界时,背景颜色变为绿色。现在,当鼠标离开子菜单的边界时,我想将此颜色更改为红色。 有什么建议么 ?
protected override void OnPaint(PaintEventArgs e)
{
base.OnPaint(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));
}