C#如何更改menuStrip悬停颜色?
您无法使用正常MouseEnter
和MouseLeave
事件做到这一点。您需要直接覆盖菜单渲染。你可以做这样的事情,使用MenuStrip
类:
private class renderer : ToolStripProfessionalRenderer {
public renderer() : base(new cols()) {}
}
private class cols : ProfessionalColorTable {
public override Color MenuItemSelected {
// when the menu is selected
get { return Color.Blue; }
}
public override Color MenuItemSelectedGradientBegin {
get { return Color.Black; }
}
public override Color MenuItemSelectedGradientEnd {
get { return Color.White; }
}
}
以防万一你有兴趣,这是当你使用MouseEnter
和MouseLeave
事件会发生什么。 (里面的MouseEnter
事件,它是使BackgroundColor
绿色的,但是这并没有被调用):
正是我一直在寻找的,谢谢你,先生。 –
很高兴能帮到你。注意你可以用'ProfessionalColorTable'类做更多的事情。请参阅此MSDN文章:https://msdn.microsoft.com/en-us/library/System.Windows.Forms.ProfessionalColorTable(v=vs.110).aspx – carefulnow1
“Enter”和“Leave”方法在哪里在说什么?为什么背景应该是绿色的? – Shaharyar
不,它不是。我想改变主要项目悬停颜色,并且在那个问题上没有关于它的文字颜色 –
? – Shaharyar
不行,文字背景 –