Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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

like image 712
Joan Venge Avatar asked Dec 15 '11 22:12

Joan Venge


People also ask

What is a ToolStrip c#?

ToolStrip control provides functionality of Windows toolbar controls in Visual Studio 2010. ToolStrip class represents a ToolStrip control in Windows Forms and serves as a base class of MenuStrip, StatusStrip, and ContextMenuStrip classes.


3 Answers

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
    }
}
like image 55
2Toad Avatar answered Oct 17 '22 02:10

2Toad


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.

like image 22
Dracorat Avatar answered Oct 17 '22 01:10

Dracorat


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.

like image 3
phadaphunk Avatar answered Oct 17 '22 02:10

phadaphunk