1

have Googled and cannot find out how to make a ToolStripSeparator "draw" an horizontal line in a toolbar that is aligned vertical.

The separator is drawn vertically which makes it awful.

Eg.
* - item

*
*
| <- separator
*
*

when it should be

*
*
- <- separator
*
*

Ian Boyd
  • 246,734
  • 253
  • 869
  • 1,219
Marcus
  • 1,866
  • 1
  • 20
  • 33
  • I'm giving this the "Works-On-My-Machine" seal of approval. :) I'm looking at a ToolStripSeparator in a vertical toolstrip right now. The separator is painted horizontally - both in design and at runtime. – Yoopergeek Oct 21 '09 at 14:21
  • i guess a screenshot would be in order. – Ian Boyd Oct 21 '09 at 14:25
  • Yeah, I was wondering, but I supplied an answer on how to custom draw it anyway. ;) – J. Steen Oct 21 '09 at 14:25
  • http://img63.imageshack.us/img63/484/separatorerror.jpg – Marcus Oct 21 '09 at 14:35
  • 1
    found the problem must be: ToolStrip.LayoutStyle = ToolStripLayoutStyle.VerticalStackWithOverflow else you get the problem I had. – Marcus Oct 21 '09 at 14:48

1 Answers1

1

You can create your own ToolStripRenderer and override the OnRenderSeparator to draw the line yourself.

protected override void OnRenderSeparator(ToolStripSeparatorRenderEventArgs e)
{
    using (var pen = new Pen(borderColor))
    {
        e.Graphics.DrawLine(pen, 5, e.Item.Size.Height / 2, e.Item.Size.Width - 5, e.Item.Size.Height / 2);
    }
}

Then you set the Renderer property of your toolstrip to the renderer you just made.

toolStrip.Renderer = new MyToolStripRenderer();
J. Steen
  • 15,470
  • 15
  • 56
  • 63