如何删除 ToolStrip Winforms 控件一角的这种奇怪的视觉伪影?

发布于 2024-12-21 06:19:37 字数 253 浏览 3 评论 0原文

这是显示问题的图片。看一下右下角。

有人知道如何摆脱它吗?

LayoutStyle 设置为 VerticalStackWithOverflow 可以修复此问题,但也会使项目水平居中,这是我不想要的。

我只想要一个如图所示的垂直堆栈,但右下角没有黑线。

在此处输入图像描述

Here is the picture that shows the problem. Take a look at the bottom right corner.

Anyone knows how to get rid of it?

Setting LayoutStyle to VerticalStackWithOverflow fixes it but also centers the items horizontally which I don't want.

I just want a vertical stack like in the pic, but without that black line in the bottom right corner.

enter image description here

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

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

发布评论

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

评论(3

半暖夏伤 2024-12-28 06:19:37

很抱歉参加聚会迟到,但接受的答案无法满足我的需求。以下解决方案是我想出的:

摆脱黑线

1)创建自定义渲染器:

class CustomToolStripProfessionalRenderer : ToolStripProfessionalRenderer
{
    protected override void OnRenderToolStripBorder(ToolStripRenderEventArgs e)
    {
        // Don't draw a border
    }
}

2)使用自定义渲染器:

toolStrip1.Renderer = new CustomToolStripProfessionalRenderer();

摆脱背景

上面的解决方案满足了原始问题的需要,但我没有'也不喜欢 ToolStrip 上的渐变背景。我希望 ToolStrip 成为一个“隐形”容器:

1)创建自定义颜色表:

class CustomProfessionalColorTable : ProfessionalColorTable
{
    public override Color ToolStripGradientBegin
    {
        get { return SystemColors.Control; }
    }

    public override Color ToolStripGradientMiddle
    {
        get { return SystemColors.Control; }
    }

    public override Color ToolStripGradientEnd
    {
        get { return SystemColors.Control; }
    }
}

2)使用自定义颜色表:

class CustomToolStripProfessionalRenderer : ToolStripProfessionalRenderer
{
    public CustomToolStripProfessionalRenderer()
        : base(new CustomProfessionalColorTable())
    {

    }

    protected override void OnRenderToolStripBorder(ToolStripRenderEventArgs e)
    {
        // Don't draw a border
    }
}

Sorry for being late to the party, but the accepted answer didn't work for my needs. The following solution is what I came up with:

Getting rid of the black line

1) Create a custom renderer:

class CustomToolStripProfessionalRenderer : ToolStripProfessionalRenderer
{
    protected override void OnRenderToolStripBorder(ToolStripRenderEventArgs e)
    {
        // Don't draw a border
    }
}

2) Use the custom renderer:

toolStrip1.Renderer = new CustomToolStripProfessionalRenderer();

Getting rid of the background

The above solution satisfies the need of the original question, but I didn't like the gradient background on the ToolStrip either. I wanted the ToolStrip to be an "invisible" container:

1) Create a custom color table:

class CustomProfessionalColorTable : ProfessionalColorTable
{
    public override Color ToolStripGradientBegin
    {
        get { return SystemColors.Control; }
    }

    public override Color ToolStripGradientMiddle
    {
        get { return SystemColors.Control; }
    }

    public override Color ToolStripGradientEnd
    {
        get { return SystemColors.Control; }
    }
}

2) Use the custom color table:

class CustomToolStripProfessionalRenderer : ToolStripProfessionalRenderer
{
    public CustomToolStripProfessionalRenderer()
        : base(new CustomProfessionalColorTable())
    {

    }

    protected override void OnRenderToolStripBorder(ToolStripRenderEventArgs e)
    {
        // Don't draw a border
    }
}
长梦不多时 2024-12-28 06:19:37

在属性栏中,将“RenderMode”设置为“System”或使用

.RenderMode = System.Windows.Forms.ToolStripRenderMode.System;

执行此操作会将 .BackColor 更改为“Control”,但如果需要,您可以在之后更改。

In the properties bar, set "RenderMode" to "System" or use

.RenderMode = System.Windows.Forms.ToolStripRenderMode.System;

Doing this will change the .BackColor to "Control" but you can change that after if you want.

朮生 2024-12-28 06:19:37

我认为最好的办法是在属性中将 RenderMode 设置为 System,并将布局属性保留为 Horizo​​ntalStackWithOverflow
但前提是您不介意更改工具提示绘制样式。

I think your best shot would be to set the RenderMode to System in the properties and leave the layout properties to HorizontalStackWithOverflow.
But that is if you don't mind changing the tooltip paint style.

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