Rounded Corners ToolStrip

I am working on a Windows Form application (C #, .NET 4.0, VS 2010), where I have a pretty standard MainForm with ToolStrip (GripStyle: Hidden, Dock: Top, RenderMode: ManagerRenderMode). The toolbar contains several basic elements (ToolStripLabel, ToolStripSeparator, ToolStripSplitButton).

This is displayed as follows:

ToolStrip rendered by default ManagerRenderMode

At first, I just wanted to add a lower border under the toolbar, but I also noticed that this toolbar is displayed with rounded corners (you can see the upper and lower sides of the right side of the image) and a vertical gradient line.

How to make these corners NOT rounded?

I tried:

public class MainFormToolStripRenderer : ToolStripProfessionalRenderer { protected override void OnRenderToolStripBorder(ToolStripRenderEventArgs e) { base.OnRenderToolStripBorder(e); var y = e.ToolStrip.Height-1; e.Graphics.DrawLine(new Pen(SystemColors.ControlDark, 1), new Point(0, y), new Point(e.ToolStrip.Width, y)); } 

And connected it through this.toolStrip_Actions.Renderer=new MainFormToolStripRenderer(); in my form initialization.

This gave me a lower bound, but did nothing for rounded corners. In addition, with the added lower border, rounded corners become more noticeable:

ToolStrip rendered by custom ToolStripProfessionalRenderer

Next, I tried to draw a rectangle during the same event handler in order to try (at least) to hide rounded corners and a vertical gradient behind a solid rectangular frame. This did not work because the available drawing area (e.AffectedBounds) is within rounded borders.

I also tried installing ToolStrip RenderMode on the system (and not using my renderer). In this case, the corners of the toolbar seem to fit snugly (rectangular), but the shared button in the toolbar seems to be broken (pressing the down arrow does not display a dropdown menu) for unknown reasons and the general appearance of -feel is slightly suppressed (rather flat while you don’t hover over some buttons in the toolstrip).

I assume that in the end I would prefer to use the ManageeRenderedMode or my own render, inheriting from Professional, but I need to get rid of the rounded corners. In particular, I found this SO Q , which seems to indicate that I am watching, but did not give me an answer to my case.

Thanks in advance

+6
source share
3 answers

Try this in the rendering class:

 public class MainFormToolStripRenderer : ToolStripProfessionalRenderer { public MainFormToolStripRenderer() { this.RoundedEdges = false; } } 
+9
source

As mentioned in am05mhz, just select RenderMode> System and the rounded corners will disappear:

+2
source

Based on the accepted answer on LarsTech , you don’t have to run the new Renderer class unless there are good reasons for this.

You can do this as one liner as follows:

 toolStrip_Actions.Renderer = new ToolStripProfessionalRenderer() { RoundedEdges = false }; 

or since the default renderer for ToolStrip with RenderMode installed in ManagerRenderMode is already ToolStripProfessionalRenderer, you can use it as such and access the RoundedEdges property as follows:

 ((ToolStripProfessionalRenderer)toolStrip_Actions.Renderer).RoundedEdges = false; 
0
source

All Articles