我有我的ToolStripMenuItem
,当我运行该应用程序时,它看起来像这样:
如您所见,在ToolStripMenuItem
左边有一点空白。
如何删除?我尝试编辑每个属性,但仍然保留...
谢谢大家!
最佳答案
要更改菜单项的外观,应使用带有自定义ToolStripProfessionalRenderer
的ProfessionalColorTable
。
要更改该颜色,您应该覆盖自定义颜色表的ImageMarginGradientBegin
属性并返回所需的颜色。
例如,您可以拥有:
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());
}