dotnet / winforms

Windows Forms is a .NET UI framework for building Windows desktop applications.
MIT License
4.31k stars 957 forks source link

MenuStrip, ToolStrip and StatusStrip white border issue #5421

Open AngeloCresta opened 2 years ago

AngeloCresta commented 2 years ago

Problem description: if the "strips" have dark colors (via professional renderer) a white border (on the left for toolstrip and menustrip and statusstrip, and on the bottom for statusstrip) cannot be avoided.

White border near the form border (.Net Core 5):

image image image

Expected behavior: Same application, same "ToolStripProfessionalRenderer" in .Net Framework 4.8, the borders are drawn correctly:

image

Best Regards, Angelo

RussKie commented 2 years ago

This looks like what https://github.com/dotnet/winforms/pull/4739 is trying to address.

AngeloCresta commented 2 years ago

Agree, plus the right border on toolstrip and menustrip ;)

RussKie commented 2 years ago

Would you like to try to fix the other one?

AngeloCresta commented 2 years ago

Why not?! Let me know...

dreddy-work commented 2 years ago

Why not?! Let me know...

@AngeloCresta , please go ahead. I marked this for up for grab.

AngeloCresta commented 2 years ago

This week I had time to dig a bit into this, and I've found something interesting, the issue is not (only) with the toolbars, but it seems with the DWMComposition (*) and Windows 11 (build > 220000). If you have a custom form with no standard border (let's say 1px) and a paddind of 1 px, the composition is not able to draw the child controls docked into the parent (Form), addind at least 2px on bottom and on the right the compostion is able to round the edges, design the border, without having the ugly white space.

this shows the extra 1 px padding: image

without the padding (with a split container docked, with DWM composition(*)): image

Without the padding (with a split container docked, without DWM composition): image

I'm not sure if this helps, this issue can be closed: it'a strange but quite logical behaviour...

Ciao /// Angelo

(*)

        public static bool WindowBorderlessDropShadow(IntPtr hWnd, int ShadowSize)
        {
            MARGINS Margins = new MARGINS(0, ShadowSize, 0, ShadowSize);
            int result = DwmExtendFrameIntoClientArea(hWnd, ref Margins);
            return result;
        }

Where int ShadowSize shoud at least be 2px (to let DWM draw ...) and DwmExtendFrameIntoClientArea is:

        public static extern int DwmExtendFrameIntoClientArea(IntPtr hWnd, ref MARGINS pMarInset);
       [DllImport("dwmapi.dll")]
ghost commented 2 years ago

This issue is now marked as "up for grabs", and we’re looking for a community volunteer to work on this issue. If we receive no interest in 120 days, we will close the issue. To learn more about how we handle feature requests, please see our documentation.

Happy Coding!