问题
I have some menustrip Items in my menustrip.I want to set the color of the menustrip item when the mouse is on the menustripitem.Is it possible to have mouseover event for a menustripitem.
Thanks in Advance.
回答1:
You need to create your own renderer and assign the MenuStrip.Renderer property. Here's an example, it is going to need some work to look better:
public partial class Form1 : Form {
public Form1() {
InitializeComponent();
menuStrip1.Renderer = new MyRenderer();
}
private class MyRenderer : ToolStripProfessionalRenderer {
protected override void OnRenderMenuItemBackground(ToolStripItemRenderEventArgs e) {
if (e.Item.Selected) {
e.Graphics.FillRectangle(Brushes.Bisque, e.Item.Bounds);
}
else base.OnRenderMenuItemBackground(e);
}
}
}
回答2:
You should use MouseEnter event of menustripitem.
来源:https://stackoverflow.com/questions/7415202/mouseover-event-for-menustripitem