本文介绍了删除ToolStripMenuItem左边框的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有我的 ToolStripMenuItem ,运行应用程序时,它看起来像这样:

I have my ToolStripMenuItem and when I run the application, it looks like this:

如您所见,在 ToolStripMenuItem 左。

如何删除它?我尝试编辑每个属性,但仍然保留...

How can I remove it? I tried to edit every property but it still remains...

谢谢大家!

推荐答案

要更改菜单项的外观,应使用 ToolStripProfessionalRenderer 和自定义的 ProfessionalColorTable

To change appearance of menu item you should use a ToolStripProfessionalRenderer using a custom ProfessionalColorTable.

要更改该颜色,您应该覆盖自定义颜色表的 ImageMarginGradientBegin 属性并返回所需的颜色。

To change that color, you should override ImageMarginGradientBegin property of custom color table and return the color you want.

例如,您可以拥有:

public class CustomColorTable : ProfessionalColorTable
{
    public override Color ImageMarginGradientBegin
    {
        get { return Color.Red; }
    }
    public override Color ImageMarginGradientMiddle
    {
        get { return Color.Green; }
    }
    public override Color ImageMarginGradientEnd
    {
        get { return Color.Blue; }
    }
    public override Color ToolStripDropDownBackground
    {
        get { return Color.Yellow; }
    }

    public override Color MenuItemSelected
    {
        get { return Color.Pink; }
    }

    //You should also override other properties if you need.
    //This is just a sample code to show you the solution
}

然后在表单中加载:

private void Form_Load(object sender, EventArgs e)
{
    ToolStripManager.Renderer = new ToolStripProfessionalRenderer(new CustomColorTable());
}

这篇关于删除ToolStripMenuItem左边框的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-11 00:56