在 WinForms 的垂直工具栏中制作水平 ToolStripSeparator

发布于 2024-08-08 16:09:06 字数 230 浏览 3 评论 0原文

已在 Google 上搜索,无法找到如何使 ToolStripSeparator 在工具栏中“绘制”垂直对齐的水平线。

分隔符是垂直绘制的,这使得它很糟糕。

例如。
* - 项目

*
*
| <- 分隔符
*
*

应该是

*
*
- <- 分隔符
*
*

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

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

月竹挽风 2024-08-15 16:09:06

您可以创建自己的 ToolStripRenderer 并重写 OnRenderSeparator 来自己绘制线条。

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);
    }
}

然后将工具条的 Renderer 属性设置为刚刚创建的渲染器。

toolStrip.Renderer = new MyToolStripRenderer();

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();
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文