3

I am developing a winforms application using all those flat style options, and it makes the application look a lot like Win10 applications, so I was wondering if is it possible to detect if the OS is using dark mode, so I could adjust the colors to fit the dark (or light) mode.

I found some questions about it, but they were related to UWP and WPF, so the solutions didn't work on my apllication.

Gabic
  • 484
  • 1
  • 6
  • 15

2 Answers2

4

You can read the current user preferences from the Windows Registry:

HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Themes\Personalize

enter image description here

Waescher
  • 5,361
  • 3
  • 34
  • 51
  • 1
    Brilliant! Took me a while to find out how to access the value via code, but it worked perfectly! Thank you very much! – Gabic Jun 09 '20 at 13:35
4

Based on Waescher's solution, here is the code for that:

using Microsoft.Win32;

try
{
    int res = (int)Registry.GetValue("HKEY_CURRENT_USER\\SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Themes\\Personalize", "AppsUseLightTheme", -1);
}
catch 
{
 //Exception Handling     
}
    

res contains the value for the default theme on windows

0 : dark theme

1 : light theme

-1 : AppsUseLightTheme could not be found

Rena821
  • 149
  • 7