Question

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...

toolstrip

My question is how do I get rid of the "drop shadow" effect I.e. 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.

Was it helpful?

Solution

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.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top