How to remove this strange visual artifact in the corner of ToolStrip Winforms control?

只愿长相守 提交于 2019-12-03 05:43:33

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.

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

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.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!