我在我的 C# winforms 应用程序 (VS2010) 中的 bindingnavigator 工具条上做了一些样式设置,主要是设置背景颜色并去掉分隔线。现在看起来是这样的……
我的问题是如何摆脱“阴影”效果,即工具条下方和右侧的白色单像素线。我尝试调整 bindingnavigator 本身及其成员项的大小、边距和填充,但没有成功。
我在我的 C# winforms 应用程序 (VS2010) 中的 bindingnavigator 工具条上做了一些样式设置,主要是设置背景颜色并去掉分隔线。现在看起来是这样的……
我的问题是如何摆脱“阴影”效果,即工具条下方和右侧的白色单像素线。我尝试调整 bindingnavigator 本身及其成员项的大小、边距和填充,但没有成功。
创建一个SystemRenderer
:
public class MyToolStripSystemRenderer : ToolStripSystemRenderer
{
public MyToolStripSystemRenderer() { }
protected override void OnRenderToolStripBorder(ToolStripRenderEventArgs e)
{
//Making this non-op removes the artifact line that is typically drawn on the bottom edge
//base.OnRenderToolStripBorder(e);
}
}
..然后在你的ToolStrip
类的构造函数中使用它:
public MyToolStrip()
{
Renderer = new MyToolStripSystemRenderer();
}
如果这不是继承的ToolStrip
控件,而是来自 Designer 的库存控件,则在Designer.cs
文件中查找设置 ToolStrip 属性的行。在我的情况下,它看起来像这样:
this.toolStrip1.Location = new System.Drawing.Point(0, 0);
this.toolStrip1.Name = "toolStrip1";
this.toolStrip1.Size = new System.Drawing.Size(678, 25);
this.toolStrip1.TabIndex = 10;
this.toolStrip1.Text = "toolStrip1";
再加上这一行:
this.toolStrip1.Renderer = new MyToolStripSystemRenderer();
**请注意,如果您愿意,可以将同一行添加到表单的构造函数中。一样的效果。