dotnet / winforms

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

Dark mode, the scroll bar theme is incorrect. #10665

Closed EVA-SS closed 8 months ago

EVA-SS commented 8 months ago

.NET version

.net6.0

Did it work in .NET Framework?

Yes

Did it work in any of the earlier releases of .NET Core or .NET 5+?

all

Issue description

After enabling dark mode, the scroll bar remains in the light theme.

DarkTestGIF

        private void button1_Click(object sender, EventArgs e)
        {
            Dark = !Dark;
        }

        bool dark = false;
        public bool Dark
        {
            get => dark;
            set
            {
                dark = value;
                if (value)
                {
                    BackColor = Color.Black;
                    ForeColor = Color.White;
                }
                else
                {
                    BackColor = Color.White;
                    ForeColor = Color.Black;
                }
                int useImmersiveDarkMode = value ? 1 : 0;
                DwmSetWindowAttribute(Handle, DWMWA_USE_IMMERSIVE_DARK_MODE, ref useImmersiveDarkMode, sizeof(int));
            }
        }

        #region DarkDwm

        [DllImport("dwmapi.dll")]
        static extern int DwmSetWindowAttribute(IntPtr hwnd, int attr, ref int attrValue, int attrSize);

        const int DWMWA_USE_IMMERSIVE_DARK_MODE = 20;

        #endregion

DarkTest.zip

Steps to reproduce

After invoking "Dark=true", the scroll bar color remains in the light theme.

elachlan commented 8 months ago

Call Invalidate() after the call to DwmSetWindowAttribute. https://stackoverflow.com/a/62811758

EDIT: unsure if that will actually help.

merriemcgaw commented 8 months ago

We are unable to change the background color of scrollbars. This is an area that we're looking at for the theming and seeing if we can get a solution in the future. For now, this is a known issue.

EVA-SS commented 8 months ago

😭Alright, this is pretty frustrating, I'm really hoping to get some good news from you guys.

elachlan commented 8 months ago

@EVA-SS I'd encourage you to investigate a solution if you have the time and ability. Especially if this is blocking you and your app.

elachlan commented 8 months ago

This looks promising!

The WM_CTLCOLORSCROLLBAR message is used only by child scroll bar controls. Scrollbars attached to a window (WS_SCROLL and WS_VSCROLL) do not generate this message. To customize the appearance of scrollbars attached to a window, use the flat scroll bar functions.

And disappointment:

Flat scroll bars are supported by Comctl32.dll versions 4.71 through 5.82. Comctl32.dll versions 6.00 and later do not support flat scroll bars.

EVA-SS commented 8 months ago

This looks promising!

The WM_CTLCOLORSCROLLBAR message is used only by child scroll bar controls. Scrollbars attached to a window (WS_SCROLL and WS_VSCROLL) do not generate this message. To customize the appearance of scrollbars attached to a window, use the flat scroll bar functions.

And disappointment:

Flat scroll bars are supported by Comctl32.dll versions 4.71 through 5.82. Comctl32.dll versions 6.00 and later do not support flat scroll bars.

🙂 Thank you for bringing up the idea, FlatSB can indeed change the scrollbar style. As you pointed out, there are some issues with it, and it's not perfect. overriding the native scrollbar is a challenging task indeed.

elachlan commented 8 months ago

Maybe its something that can be done using VisualStyles and the ScrollBarRenderer?

EVA-SS commented 8 months ago

4479 #2040 I think currently, ScrollBarRenderer isn't up to the task.

elachlan commented 8 months ago

@EVA-SS Are you happy for me to close this issue in favor of those issues?

EVA-SS commented 8 months ago

okay

KlausLoeffelmann commented 6 months ago

10985