开发者

Making a ToolStripSeparator horizontal in a vertical toolbar in WinForms

开发者 https://www.devze.com 2022-12-08 21:50 出处:网络
have Googled and cannot find out how to make a ToolStripSeparator \"draw\" an horizontal line in a toolbar that is aligned vertical.

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

精彩评论

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