Introduction
Learn how to support dark mode for Windows Forms projects targeting .NET 9 Core Framework.
Although this is an experimental feature, dark mode appears to work fine.
Why dark mode?
There are customers who simply prefer dark mode while others it may be that light mode is difficult to work with, an accessibility issue. Either way having the ability to offer dark mode is a plus.
How to implement
Add the following PropertyGroup to your project file:
<PropertyGroup>
<NoWarn>$(NoWarn);WFO5001</NoWarn>
</PropertyGroup>
Or use #pragma warning disable WFO5001 directive to suppress the error where it occurs instead of disabling it for the entire project.
Next add to Program.cs Application.SetColorMode(SystemColorMode.Dark); before Application.Run(new Form1());.
Once the above is in place, build and run the project.
Dynamic mode
Rather than hard code dark mode, a better idea is to start off with light mode and provide an option for light, system or dark mode.
Example Window child form (included with source code) that provides a way to change and persist color mode to appsettings.json file.
Comments
Since dark mode is experimental some controls may not present as each developer wants them. For instance, a DataGridView. In the provided code check out the following language extension method.
public static void ColorizeDarkModeHeaders(this DataGridView source)
{
source.EnableHeadersVisualStyles = false;
source.ColumnHeadersDefaultCellStyle.BackColor = Color.Blue;
}
Which presents as follows.
Not what you expect?
If something does not appear correct, ask on Stackoverflow and when asking write a well formed question.
Summary
With the provided code, thanks to Microsoft developers can implement dark, system and light mode in Window Form projects.
Take time to study the provided code rather than simply copy and pasting provided code into a project.
As with any experimental feature there may be changes in future editions of the .NET Framework.

SOCIAL SHARE CARD GENERATOR