How to disable the line under tool strip in winform c#?

旧街凉风 提交于 2019-11-29 22:38:06
sgoldyaev

It's a bug in the "system" renderer, details in this bug report.

Microsoft's response gives a very easy workaround:

1) Create a subclass of ToolStripSystemRenderer, overriding OnRenderToolStripBorder and making it a no-op:

public class MySR : ToolStripSystemRenderer
{
    public MySR() { }

    protected override void OnRenderToolStripBorder(ToolStripRenderEventArgs e)
    {
        //base.OnRenderToolStripBorder(e);
    }
}

2) Use that renderer for your toolstrip:

toolStrip3.Renderer = new MySR();

You might want to add type check to avoid missing border on ToolStripDropDownMenu/etc. (since inherited from ToolStrip, it starts same custom renderer usage automatically):

protected override void OnRenderToolStripBorder(ToolStripRenderEventArgs e)
{
    if (e.ToolStrip.GetType() == typeof(ToolStrip))
    { 
        // skip render border
    }
    else
    {
        // do render border
        base.OnRenderToolStripBorder(e);
    }
}

Missed ToolStripDropDownMenu border is not so noticable while using ToolStripSystemRenderer but become real eyesore with ToolStripProfessionalRenderer.

Also, setting System.Windows.Forms.ToolStripManager.Renderer = new MySR(); could be usefull if you want all ToolStrip instances appwide to use MySR by default.

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