ダーク モード (Dark mode)

ライト モードに設定されていることは、レジストリの[HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Themes\Personalize]で、[AppsUseLightTheme]が1に設定されていることで確認できます。c# - Is it possible to detect Windows dark mode on winforms application? - Stack Overflow

Windows Form

Formアプリケーションでは、DwmSetWindowAttribute()関数でDWMWINDOWATTRIBUTEのDWMWA_USE_IMMERSIVE_DARK_MODEでTRUEを指定することでダークモードを適用できます。

HRESULT DwmSetWindowAttribute(
       HWND    hwnd,
       DWORD   dwAttribute,
  [in] LPCVOID pvAttribute,
       DWORD   cbAttribute
);
DwmSetWindowAttribute function (dwmapi.h) - Win32 apps | Microsoft Learn

C#では次のように呼び出します。

[DllImport("dwmapi.dll")]
private static extern int DwmSetWindowAttribute(HandleRef hwnd, int attribute, ref int attributeValue, int attributeValueSize);
const int DWMWA_USE_IMMERSIVE_DARK_MODE = 20;

int attribute = DWMWA_USE_IMMERSIVE_DARK_MODE;
int preference = Convert.ToInt32(true);

int result = DwmSetWindowAttribute(new HandleRef(this, this.Handle), (int)attribute, ref preference, sizeof(int));

0x80070006 (ERROR_INVALID_HANDLE) が返されることがあります。

複数の技術系サイトから、まとめて検索