1

我在我的 C# winforms 应用程序 (VS2010) 中的 bindingnavigator 工具条上做了一些样式设置,主要是设置背景颜色并去掉分隔线。现在看起来是这样的……

工具条

我的问题是如何摆脱“阴影”效果,即工具条下方和右侧的白色单像素线。我尝试调整 bindingnavigator 本身及其成员项的大小、边距和填充,但没有成功。

4

1 回答 1

2

创建一个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();

**请注意,如果您愿意,可以将同一行添加到表单的构造函数中。一样的效果。

于 2014-01-21T18:46:07.850 回答