C#, BindingNavigator, Ugly line at the right end

2019-07-15 03:51发布

问题:

How do I get rid of this ugly line?

Draw a default bindingnavigator on an empty Form and you will see the problem. RenderMode is ManagerRenderMode. I want this render mode so the mouse over colors is correct. However, If I switch to System as rendermode the ugly line disapears, but then mouse over color/effect gets ugly.

I have been looking around for a solution for some time now, but nothing. Maybe someone here have seen this problem before?

回答1:

It's not a BindingNavigator specific issue, but the ToolStrip which BindingNavigator inherits.

It's caused by the DrawToolStripBorder method when the ToolStripProfessionalRenderer class RoundedEdges property is true (the default).

In order to turn it off, I can suggest the following helper method:

public static class WindowsFormsExtensions
{
    public static void DisableRoundedEdges(this ToolStripRenderer renderer)
    {
        var professionalRenderer = renderer as ToolStripProfessionalRenderer;
        if (professionalRenderer != null)
            professionalRenderer.RoundedEdges = false;
    }
}

Now you can turn it off for the specific control (it's not available at design time, so it has to be at run time inside your form/control constructor or load event):

this.bindingNavigator1.Renderer.DisableRoundedEdges();

or to disable it globally, add the following in your Main method before calling Application.Run:

ToolStripManager.Renderer.DisableRoundedEdges();