I created a C# class using @Jonas Kohls answer from here
The class works like a charm and makes it easy to work with multiple forms just call DarkTitleBarClass.UseImmersiveDarkMode(Handle, true);
in your load method.
I used this when upgrading some old WinForms apps so its WinForm friendly but only tested on win 8,10 and 11
Example image below Winforms .NetCore 6.0

using System.Runtime.InteropServices;
namespace Myapp.Classes
{
internal class DarkTitleBarClass
{
[DllImport("dwmapi.dll")]
private static extern int DwmSetWindowAttribute(IntPtr hwnd, int attr,
ref int attrValue, int attrSize);
private const int DWMWA_USE_IMMERSIVE_DARK_MODE_BEFORE_20H1 = 19;
private const int DWMWA_USE_IMMERSIVE_DARK_MODE = 20;
internal static bool UseImmersiveDarkMode(IntPtr handle, bool enabled)
{
if (IsWindows10OrGreater(17763))
{
var attribute = DWMWA_USE_IMMERSIVE_DARK_MODE_BEFORE_20H1;
if (IsWindows10OrGreater(18985))
{
attribute = DWMWA_USE_IMMERSIVE_DARK_MODE;
}
int useImmersiveDarkMode = enabled ? 1 : 0;
return DwmSetWindowAttribute(handle, attribute, ref useImmersiveDarkMode, sizeof(int)) == 0;
}
return false;
}
private static bool IsWindows10OrGreater(int build = -1)
{
return Environment.OSVersion.Version.Major >= 10 && Environment.OSVersion.Version.Build >= build;
}
}
}
[EDIT] Don't forget to add a app.manifest
and uncomment the appropriate supported OS.