Home > Mobile >  Windows Form ToolStripButton Flat Style (Visual Studio Alike)
Windows Form ToolStripButton Flat Style (Visual Studio Alike)

Time:07-27

I'm working with C# on a windows form application (.NETFramework 4.8) and I'm trying to make a ToolStrip menu that looks very flat like the Visual Studio toolbars, how can this be done? I also cant get rid of the white line under the toolstrip.

This is the best result so far (I selected the same background colors but they look different):

This is the best result so far

This what I have in mind:

this what I have in mind

Thanks.

CodePudding user response:

could you be more clear about what do you mean by "flat" please ?

I tested the creation of one ToolStrip, added two buttons in it, set the DisplayStyle property of both of them to "Text", and I get that: "Flat" toolstrip buttons

How could it be "flatter" ? What problem do you have with the ToolStrip exactly ?

Thank you in advance, have a nice day !

Edit:

I see your problem, and following that link, You can get the solution. The solution is, create your own ToolStrip border Renderer that does nothing.

The problem is basically a bug in the built-in Microsoft's Toolstrip renderer, which we can fix by creating our own without telling to render these borders.

To do so, go to the concerned Form, click the arrow left to it, go to [form].Designer.cs, and add this code before the form class:

    public class MySR: System.Windows.Forms.ToolStripSystemRenderer
    {
        public MySR() { }
        protected override void OnRenderToolStripBorder(ToolStripRenderEventArgs e){}
    }

And set the "Renderer" property of the ToolStrip to "new MySr()", still in the same file, in the Form's "InitializeComponent" function:

// 
//[Your toolstrip name, let's say myToolStrip]
//
this.myToolStrip.Renderer = new MySR();

Hope it can help ! Have a nice day.

  • Related