Belfed
Belfed

Reputation: 165

Remove the ToolStripMenuItem left border

I have my ToolStripMenuItem and when I run the application, it looks like this:

enter image description here

As you can see, there is a little white space at the ToolStripMenuItem left.

How can I remove it? I tried to edit every property but it still remains...

Thank you all in advance!

Upvotes: 3

Views: 942

Answers (1)

Reza Aghaei
Reza Aghaei

Reputation: 125332

To change appearance of menu item you should use a ToolStripProfessionalRenderer using a custom ProfessionalColorTable.

To change that color, you should override ImageMarginGradientBegin property of custom color table and return the color you want.

enter image description here

For example you can have :

public class CustomColorTable : ProfessionalColorTable
{
    public override Color ImageMarginGradientBegin
    {
        get { return Color.Red; }
    }
    public override Color ImageMarginGradientMiddle
    {
        get { return Color.Green; }
    }
    public override Color ImageMarginGradientEnd
    {
        get { return Color.Blue; }
    }
    public override Color ToolStripDropDownBackground
    {
        get { return Color.Yellow; }
    }

    public override Color MenuItemSelected
    {
        get { return Color.Pink; }
    }

    //You should also override other properties if you need.
    //This is just a sample code to show you the solution
}

And then in your form load:

private void Form_Load(object sender, EventArgs e)
{
    ToolStripManager.Renderer = new ToolStripProfessionalRenderer(new CustomColorTable());
}

Upvotes: 5

Related Questions