简体   繁体   English

悬停并单击时如何更改ToolStripMenuItem的默认背景色?

[英]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.

相关问题 单击x并通过系统托盘ToolStripMenuItem删除时如何隐藏窗口表单 - How do I hide a window form when x is clicked and CLose through system tray ToolStripMenuItem 如何在单击或选项卡时将文本框字体更改回默认值并清除默认文本? - How do I change textbox font back to default and clear default text when click or tabbed to? 单击时启用/禁用ToolStripMenuItem - Enabling / Disabling ToolStripMenuItem when clicked 在C#WinForm中单击子ToolStripMenuItem时,ToolStripMenuItem未关闭 - ToolStripMenuItem not closing when a child ToolStripMenuItem is Clicked in a C# WinForm WP7单击时如何更改按钮的图像 - WP7 How do I change the image of a button when clicked 如何获得默认颜色作为默认主题 - How do I get default colors to my default theme 如何关闭设置为autoclose = false的toolstripmenuitem? - How do I close a toolstripmenuitem that is set to autoclose = false? 如何为ToolStripMenuItem项目数组创建实例? - How do i make instance for array of ToolStripMenuItem items? 如何检查ToolStripMenuItem DropDownItems中是否已存在项目? - How do I check if items already exist in a ToolStripMenuItem DropDownItems? 为什么我不能使ToolStripMenuItem == True? 如何检查菜单项是否被单击? - Why can't I make a ToolStripMenuItem == True? How can I check to see if the menu item was clicked?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM