I have Windows Forms program in .NET 8, and I use the Explorer Browser from Windows API Codepack.
I am trying to add dark mode to my program, however, even when Windows is set to dark mode, the explorer in the winform is in light mode, and in the properties there isnt any attribute to set it to dark mode.
I tried using dwm immersive dark mode, but it doesnt change it to dark mode and just returns false
private const int DWMWA_USE_IMMERSIVE_DARK_MODE = 20;
[DllImport("dwmapi.dll", PreserveSig = true)]
public static extern int DwmSetWindowAttribute(IntPtr hwnd, int attr, ref int attrValue, int attrSize);
public static bool UseImmersiveDarkMode(IntPtr handle, bool enabled)
{
if (Environment.OSVersion.Version.Major >= 10)
{
int useImmersiveDarkMode = enabled ? 1 : 0;
return DwmSetWindowAttribute(handle, DWMWA_USE_IMMERSIVE_DARK_MODE, ref useImmersiveDarkMode, sizeof(int)) == 0;
}
return false;
}
and in form load function:
UseImmersiveDarkMode(explorerBrowser1.Handle, true);
Is there any way to make the embedded explorer dark?