[英]How do I change the default back colors of a ToolStripMenuItem when hovered and clicked?
Just attempting to make my UI less Windows-looking. 只是试图使我的UI看起来不像Windows。 I was testing a few of the item's events and tried controlling the background using the BackColor property, but to no avail.
我正在测试一些项目的事件,并尝试使用BackColor属性控制背景,但无济于事。 Is there any convenient way to alter the default colors?
有什么方便的方法可以更改默认颜色?
Thanks in advance. 提前致谢。
The menu item's back color turns light-blue when hovered by the cursor. 当光标悬停时,菜单项的背景色变为浅蓝色。
When an item is clicked, its back color turns light-gray, making the item's text hardly visible. 单击某个项目时,其背面颜色变为浅灰色,使得该项目的文本几乎不可见。
Simply create your ow color table from the ProfessionalColorTable. 只需从ProfessionalColorTable创建您的颜色表。
private class MyColours : ProfessionalColorTable
{
public override Color MenuItemSelected
{
get { return Color.Blue; }
}
public override Color MenuItemSelectedGradientBegin
{
get { return Color.DarkCyan; }
}
public override Color MenuItemSelectedGradientEnd
{
get { return Color.Cyan; }
}
public override Color MenuItemPressedGradientBegin
{
get { return Color.Cyan; }
}
public override Color MenuItemPressedGradientEnd
{
get { return Color.Cyan; }
}
}
Add another class to render these colors as follows. 添加另一个类以呈现这些颜色,如下所示。
private class NewColourRenderer : ToolStripProfessionalRenderer
{
public NewColourRenderer(): base(new MyColours()){}
}
Then use your new renderer in the form load event: 然后在表单加载事件中使用新的渲染器:
menuStrip1.Renderer = new NewColourRenderer();
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.