This question already has answers here:
How to change menu hover color

(4个答案)


已关闭8年。




我在我的应用程序中添加了MenuStrip,并在ManagerRenderMode上添加了Render Mode。问题是外观,内脏。看这两张照片,我想将子菜单的白色边框更改为透明,将蓝色矩形的菜单更改为灰色,将菜单和深灰色的子菜单更改为深灰色(其边框为深蓝色),将边框更改为白色选择菜单的时间。我该怎么做?
BackColor是:36; 36; 36ForeColorLightGray



我设法更改了蓝色矩形,选择了选项时选择了白色矩形,选择了子菜单选项时选择了蓝色矩形,但是我不知道如何更改white border,请帮忙。

这是到目前为止的代码...
        Color culoare = Color.FromArgb(20, 20, 20);
        Color culoare1 = Color.FromArgb(36, 36, 36);

        public override Color MenuItemSelected
        {
            get { return culoare; }
        }

        public override Color MenuItemBorder
        {
            get { return culoare; }
        }

        public override Color MenuItemSelectedGradientBegin
        {
            get { return culoare; }
        }

        public override Color MenuItemSelectedGradientEnd
        {
            get { return culoare; }
        }

        public override Color MenuItemPressedGradientBegin
        {
            get { return culoare; }
        }

        public override Color MenuItemPressedGradientEnd
        {
            get { return culoare; }
        }

        public override Color MenuBorder
        {
            get { return culoare; }
        }

最佳答案

您可以通过创建自己的ColorTable并覆盖要更改其颜色的属性来做到这一点:

public  class TestColorTable : ProfessionalColorTable
{
    public override Color MenuItemSelected
    {
        get { return Color.Red; }
    }

    public override Color MenuBorder  //added for changing the menu border
    {
        get { return Color.Green; }
    }

}

您可以这样使用它:
private void Form1_Load(object sender, EventArgs e)
{
    menuStrip1.Renderer = new ToolStripProfessionalRenderer(new TestColorTable());
}

关于c# - 如何更改MenuStrip的外观,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/13235627/

10-10 18:35
查看更多