'Is it possible to detect Windows dark mode on winforms application?
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.
Solution 1:[1]
You can read the current user preferences from the Windows Registry:
HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Themes\Personalize
Solution 2:[2]
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
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|---|
Solution 1 | Waescher |
Solution 2 | Rena821 |