Skip to content

Commit 3aeafc3

Browse files
Refactor System-handling for SetColor.
1 parent 6c0a092 commit 3aeafc3

File tree

1 file changed

+5
-4
lines changed

1 file changed

+5
-4
lines changed

src/System.Windows.Forms/src/System/Windows/Forms/Application.cs

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ public sealed partial class Application
5050

5151
private const string DarkModeKeyPath = "HKEY_CURRENT_USER\\SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Themes\\Personalize";
5252
private const string DarkModeKey = "AppsUseLightTheme";
53-
private const int SystemDarkModeDisabled = -1;
53+
private const int SystemDarkModeDisabled = 1;
5454

5555
/// <summary>
5656
/// Events the user can hook into
@@ -284,7 +284,7 @@ public static void SetColorMode(SystemColorMode systemColorMode)
284284
return;
285285
}
286286

287-
if (GetSystemColorModeInternal() > SystemDarkModeDisabled)
287+
if (GetSystemColorModeInternal() != SystemDarkModeDisabled)
288288
{
289289
s_systemColorMode = SystemColorMode.Dark;
290290
return;
@@ -367,10 +367,11 @@ private static int GetSystemColorModeInternal()
367367

368368
try
369369
{
370-
systemColorMode = (Registry.GetValue(
370+
// 0 for dark mode and |1| for light mode.
371+
systemColorMode = Math.Abs((Registry.GetValue(
371372
keyName: DarkModeKeyPath,
372373
valueName: DarkModeKey,
373-
defaultValue: SystemDarkModeDisabled) as int?) ?? systemColorMode;
374+
defaultValue: SystemDarkModeDisabled) as int?) ?? systemColorMode);
374375
}
375376
catch (Exception ex) when (!ex.IsCriticalException())
376377
{

0 commit comments

Comments
 (0)