删除ToolStripMenuItem左边框

时间:2016-05-21 19:11:14

标签: c# winforms properties designer toolstrip

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

enter image description here

如您所见,ToolStripMenuItem左侧有一些小空格。

如何删除它?我试图编辑每个房产,但它仍然是......

提前谢谢大家!

1 个答案:

答案 0 :(得分:4)

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

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

enter image description here

例如,您可以:

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());
}