From ff8cd628d0d15edd0641a66f469fb686e3e99cf5 Mon Sep 17 00:00:00 2001 From: Brandon Williams Date: Tue, 12 Nov 2024 22:09:01 -0800 Subject: [PATCH 1/2] Darken TabControl in dark mode --- .../src/System/Windows/Forms/Control.cs | 1 + .../Windows/Forms/Controls/TabControl/TabControl.cs | 11 +++++++++++ 2 files changed, 12 insertions(+) diff --git a/src/System.Windows.Forms/src/System/Windows/Forms/Control.cs b/src/System.Windows.Forms/src/System/Windows/Forms/Control.cs index 7a696612762..f3650b0626d 100644 --- a/src/System.Windows.Forms/src/System/Windows/Forms/Control.cs +++ b/src/System.Windows.Forms/src/System/Windows/Forms/Control.cs @@ -163,6 +163,7 @@ public unsafe partial class Control : internal const string ExplorerThemeIdentifier = "Explorer"; internal const string ItemsViewThemeIdentifier = "ItemsView"; internal const string ComboBoxButtonThemeIdentifier = "CFD"; + internal const string BannerContainerThemeIdentifier = "FileExplorerBannerContainer"; private const short PaintLayerBackground = 1; private const short PaintLayerForeground = 2; diff --git a/src/System.Windows.Forms/src/System/Windows/Forms/Controls/TabControl/TabControl.cs b/src/System.Windows.Forms/src/System/Windows/Forms/Controls/TabControl/TabControl.cs index 618ce40bb14..7ad176a90a1 100644 --- a/src/System.Windows.Forms/src/System/Windows/Forms/Controls/TabControl/TabControl.cs +++ b/src/System.Windows.Forms/src/System/Windows/Forms/Controls/TabControl/TabControl.cs @@ -1289,6 +1289,14 @@ protected override void OnHandleCreated(EventArgs e) } UpdateTabSelection(false); + +#pragma warning disable WFO5001 + if (Application.IsDarkModeEnabled) + { + PInvoke.SetWindowTheme(HWND, null, $"{DarkModeIdentifier}::{BannerContainerThemeIdentifier}"); + PInvokeCore.EnumChildWindows(this, StyleUpDown); + } +#pragma warning restore WFO5001 } protected override void OnHandleDestroyed(EventArgs e) @@ -1771,6 +1779,9 @@ private bool ShouldSerializeItemSize() return !_padding.Equals(s_defaultPaddingPoint); } + private BOOL StyleUpDown(HWND handle) + => PInvoke.SetWindowTheme(handle, $"{DarkModeIdentifier}_{ExplorerThemeIdentifier}", null).Succeeded; + /// /// Returns a string representation for this control. /// From 4be2d6d227bf4e360b72505b2f4974eac4d5ea01 Mon Sep 17 00:00:00 2001 From: Brandon Williams Date: Sun, 26 Jan 2025 19:05:18 -0800 Subject: [PATCH 2/2] Break the expression body after the => --- .../System/Windows/Forms/Controls/TabControl/TabControl.cs | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/src/System.Windows.Forms/src/System/Windows/Forms/Controls/TabControl/TabControl.cs b/src/System.Windows.Forms/src/System/Windows/Forms/Controls/TabControl/TabControl.cs index 1a854bf3d81..e7f29d89f80 100644 --- a/src/System.Windows.Forms/src/System/Windows/Forms/Controls/TabControl/TabControl.cs +++ b/src/System.Windows.Forms/src/System/Windows/Forms/Controls/TabControl/TabControl.cs @@ -1294,7 +1294,7 @@ protected override void OnHandleCreated(EventArgs e) if (Application.IsDarkModeEnabled) { PInvoke.SetWindowTheme(HWND, null, $"{DarkModeIdentifier}::{BannerContainerThemeIdentifier}"); - PInvokeCore.EnumChildWindows(this, StyleUpDown); + PInvokeCore.EnumChildWindows(this, StyleChildren); } #pragma warning restore WFO5001 } @@ -1779,8 +1779,9 @@ private bool ShouldSerializeItemSize() return !_padding.Equals(s_defaultPaddingPoint); } - private BOOL StyleUpDown(HWND handle) - => PInvoke.SetWindowTheme(handle, $"{DarkModeIdentifier}_{ExplorerThemeIdentifier}", null).Succeeded; + private BOOL StyleChildren(HWND handle) => + PInvoke.SetWindowTheme(handle, $"{DarkModeIdentifier}_{ExplorerThemeIdentifier}", null) + .Succeeded; /// /// Returns a string representation for this control.