15

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

Joan Venge
  • 315,713
  • 212
  • 479
  • 689

3 Answers3

16

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
    }
}
2Toad
  • 14,799
  • 7
  • 42
  • 42
14

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.

Dracorat
  • 1,184
  • 7
  • 12
  • I actually checked, it prints the BackColor as using Control before setting it to System and after. So I will change the back color to the same color values. – Joan Venge Dec 15 '11 at 23:04
  • Yes but before you change it, the custom rendered uses a slightly different color - or at least appears to - you can see a jarring difference in the look of both. But for what you're doing, I think setting a flat color of your own choosing will not be a problem - and that's only if the container has some overflow. (You might not see the background color at all depending on sizing!) – Dracorat Dec 15 '11 at 23:09
  • Actually just tried but setting the actual values manually doesn't work. Control is set to 240, 240, 240 but doing that does nothing. I assume it realizes there is an already defined color using those values so uses that instead. I set it to 245, 245, 245 and it worked. – Joan Venge Dec 15 '11 at 23:18
3

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.

phadaphunk
  • 12,785
  • 15
  • 73
  • 107