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

前端 未结 3 1671
礼貌的吻别
礼貌的吻别 2021-02-07 10:53

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

3条回答
  •  清酒与你
    2021-02-07 10:56

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

提交回复
热议问题