15

alt text

this line ?     

Glorfindel
  • 21,988
  • 13
  • 81
  • 109
monkey_boys
  • 7,108
  • 22
  • 58
  • 82

4 Answers4

56

It's a bug in the "system" renderer, details in this bug report.

Microsoft's response gives a very easy workaround:

1) Create a subclass of ToolStripSystemRenderer, overriding OnRenderToolStripBorder and making it a no-op:

public class MySR : ToolStripSystemRenderer
{
    public MySR() { }

    protected override void OnRenderToolStripBorder(ToolStripRenderEventArgs e)
    {
        //base.OnRenderToolStripBorder(e);
    }
}

2) Use that renderer for your toolstrip. The renderer must be assigned after any assignment to the toolstrip's RenderMode property or it will be overwritten with a reference to a System.Windows.Forms renderer.

toolStrip3.Renderer = new MySR();
voidp
  • 55
  • 6
sgoldyaev
  • 576
  • 5
  • 2
  • 9
    +1, but I've edited the answer to actually *include* the answer rather than only pointing to it. StackOverflow should stand alone, external links can rot. They make a good adjunct, but the main content should be on SO itself. – T.J. Crowder Mar 15 '11 at 13:28
  • Why is this shutting down my application? – RickInWestPalmBeach Jan 13 '15 at 13:59
12

You might want to add type check to avoid missing border on ToolStripDropDownMenu/etc. (since inherited from ToolStrip, it starts same custom renderer usage automatically):

protected override void OnRenderToolStripBorder(ToolStripRenderEventArgs e)
{
    if (e.ToolStrip.GetType() == typeof(ToolStrip))
    { 
        // skip render border
    }
    else
    {
        // do render border
        base.OnRenderToolStripBorder(e);
    }
}

Missed ToolStripDropDownMenu border is not so noticable while using ToolStripSystemRenderer but become real eyesore with ToolStripProfessionalRenderer.

Also, setting System.Windows.Forms.ToolStripManager.Renderer = new MySR(); could be usefull if you want all ToolStrip instances appwide to use MySR by default.

John Smith
  • 185
  • 1
  • 8
2

This class is more complete than other!

public class ToolStripRender : ToolStripProfessionalRenderer
{
    public ToolStripRender() : base() { }

    protected override void OnRenderToolStripBorder(ToolStripRenderEventArgs e)
    {
        if (!(e.ToolStrip is ToolStrip))
            base.OnRenderToolStripBorder(e);
    }
}
MiMFa
  • 981
  • 11
  • 14
1

The proposed solution to hide only toolstrip border and not dropdownmenu border does not work.

This is what does the trick:

protected override void OnRenderToolStripBorder(ToolStripRenderEventArgs e)
    {
        //if (!(e.ToolStrip is ToolStrip)) base.OnRenderToolStripBorder(e); - does not work!
        if (e.ConnectedArea.Width != 0) base.OnRenderToolStripBorder(e);
    } 
Uros Berce
  • 11
  • 2