简体   繁体   中英

How do I get rid of the drop shadow on my bindingnavigator?

I've done some styling on a bindingnavigator toolstrip in my C# winforms app (VS2010), principally setting the background colour and getting rid of dividers. It now looks like this...

工具条

My question is how do I get rid of the "drop shadow" effect Ie the white single pixel lines below and to the right of the toolstrip. I've tried tweaking the size, margins and padding of both the bindingnavigator itself and its member items but without success.

Create a 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);
    }
}

..and then make use of it in your ToolStrip class in its constructor:

public MyToolStrip()
{
    Renderer = new MyToolStripSystemRenderer();
}

If this isn't an inherited ToolStrip control, but instead a stock control from Designer, then look in the Designer.cs file for the lines that set ToolStrip properties. In mine it looks like this:

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";

Add to that, this line:

this.toolStrip1.Renderer = new MyToolStripSystemRenderer();

**Note that you could add that same line to the form's constructor if you like. Same effect.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM