开发者

Making a ToolStripSeparator horizontal in a vertical toolbar in WinForms

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.

开发者_如何学C

Eg.

* - item

*

*

| <- separator

*

*

when it should be

*

*

- <- separator

*

*


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();
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜