Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I remove the white line drawn under a MenuStrip control?

I read a few other articles about how people want to customize the colors and gradients of a MenuStrip.

What I want to do is remove the gradient so that the MenuStrip is the same color as the rest of the form which, for me, is the default settings used when creating a new WinForms project. I tried changing the RenderMode to 'System' and it works sort of, but it leaves a white line the length of the MenuStrip when I build and run it. Do I have to do some drawing and painting? Or is there an easier way?

like image 834
BrandNewDev Avatar asked Feb 16 '11 03:02

BrandNewDev


2 Answers

This is basically the same question as this one

The answer references this Microsoft bug post

It seems to be an issue all the way from 2005. Although the comments say that it is a MS bug which will not be fixed, there is a workaround which involves implementing your own renderer:

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

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

Then all you have to do is set your menustrip's renderer to the one you just implemented:

menustrip1.Renderer = new MySR();

I just tried it out and it seems to work just fine.

like image 71
Yetti Avatar answered Nov 01 '22 15:11

Yetti


I agree with Yetti but if you wish to maintain your borders you can try this. Replace Brush with your background Color

protected override void OnRenderToolStripBorder(ToolStripRenderEventArgs e)
{
  base.OnRenderToolStripBorder(e);
  e.Graphics.FillRectangle(Brushes.Black, e.ConnectedArea);
}
like image 35
General Grey Avatar answered Nov 01 '22 14:11

General Grey