DarkNet-Forms 1.0.0

Suggested Alternatives

DarkNet

Additional Details

This package was renamed to DarkNet for version 2 because there are no longer separate packages for WPF and Windows Forms. The API also changed to be more organized.

The owner has unlisted this package. This could mean that the package is deprecated, has security vulnerabilities or shouldn't be used anymore.
dotnet add package DarkNet-Forms --version 1.0.0
NuGet\Install-Package DarkNet-Forms -Version 1.0.0
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="DarkNet-Forms" Version="1.0.0" />
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add DarkNet-Forms --version 1.0.0
#r "nuget: DarkNet-Forms, 1.0.0"
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
// Install DarkNet-Forms as a Cake Addin
#addin nuget:?package=DarkNet-Forms&version=1.0.0

// Install DarkNet-Forms as a Cake Tool
#tool nuget:?package=DarkNet-Forms&version=1.0.0

This is version 1 of the DarkNet library. For version 2 and beyond, use the DarkNet package. It was renamed because there are no longer separate packages for WPF and Windows Forms.

This is a .NET library that you can use to enable Windows 10's dark mode for your application's title bars and system context menus, similar to the dark title bar in Command Prompt.

Windows Forms window with dark title bar

Requirements

  • .NET Framework 4.7.2 or later, or .NET Core 3.1 or later
  • Windows 10 version 1809 (October 2018 Update) or later for dark mode to work
    • You can run your app on earlier Windows versions, but the title bar won't turn dark
  • WPF or Windows Forms

Installation

There are two packages available, one for WPF and one for Windows Forms. You can install the one that corresponds to the GUI technology that your program uses.

WPF

dotnet add package DarkNet-WPF

See DarkNet-WPF on NuGet

Windows Forms

dotnet add package DarkNet-Forms

See DarkNet-Forms on NuGet

Usage

You must do both of the following steps.

On application startup

Before showing any windows in your application, you must call

darknet.forms.DarkNet.SetDarkModeAllowedForProcess(true);

A good place to call this is at the top of the Main() method of your application.

internal static class Program {

    [STAThread]
    private static void Main() {
        DarkNet.SetDarkModeAllowedForProcess(true);

        // Incomplete example; see below for complete example including showing your first window.
    }
}

Before showing a new window

Before showing each window in your application, you have to enable dark mode for that window.

darknet.forms.DarkNet.SetDarkModeAllowedForWindow(window, true);

You must do this before showing the window with Show() or Application.Run(). If you call it too late (such as after the window is shown), the DLL calls will have no effect on Windows.

Call the aforementioned DarkNet method after the window is constructed.

Form mainForm = new Form1();
DarkNet.SetDarkModeAllowedForWindow(mainForm, true);

You must also perform this step for all subsequent windows you show in your application, not just the first window.

Complete example

internal static class Program {

    [STAThread]
    private static void Main() {
        Application.EnableVisualStyles();
        Application.SetCompatibleTextRenderingDefault(false);
        DarkNet.SetDarkModeAllowedForProcess(true);

        Form mainForm = new Form1();
        DarkNet.SetDarkModeAllowedForWindow(mainForm, true);
        mainForm.Show();

        Application.Run(mainForm);
    }

}

Demo

Download and run darknet-demo-forms.exe from the latest release.

Windows Forms window with dark title bar

You can also clone this repository and build the darknet-demo-forms project yourself using Visual Studio Community 2019.

Limitations

  • This library currently requires a fairly recent version of Windows and the .NET runtime. This could be relaxed in a future version to allow inclusion in applications that run in a wider range of environments.
  • This library currently does not expose whether the active Windows app mode is set to Dark or Light. This may be possible to add in a future version to allow you to implement a "follow Windows app mode" strategy in your application.
  • This library only changes the theme of the title bar/window chrome/non-client area, as well as the system context menu (the menu that appears when you right click on the title bar, or left click on the title bar icon, or hit Alt+Space). It does not change the theme of the client area of your window. It is up to you to make that look different when dark mode is enabled.
  • This library currently does not help you persist a user choice for the mode they want your application to use. You can expose an option and persist that yourself, then pass the desired value to the methods in this library (e.g. call DarkNet.SetDarkModeAllowedForProcess(false) for light mode, or just don't call it at all).

Acknowledgements

Product Compatible and additional computed target framework versions.
.NET net5.0 was computed.  net5.0-windows was computed.  net6.0 was computed.  net6.0-android was computed.  net6.0-ios was computed.  net6.0-maccatalyst was computed.  net6.0-macos was computed.  net6.0-tvos was computed.  net6.0-windows was computed.  net7.0 was computed.  net7.0-android was computed.  net7.0-ios was computed.  net7.0-maccatalyst was computed.  net7.0-macos was computed.  net7.0-tvos was computed.  net7.0-windows was computed.  net8.0 was computed.  net8.0-android was computed.  net8.0-browser was computed.  net8.0-ios was computed.  net8.0-maccatalyst was computed.  net8.0-macos was computed.  net8.0-tvos was computed.  net8.0-windows was computed. 
.NET Core netcoreapp3.1 is compatible. 
.NET Framework net472 is compatible.  net48 was computed.  net481 was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.
  • .NETCoreApp 3.1

    • No dependencies.
  • .NETFramework 4.7.2

    • No dependencies.

NuGet packages

This package is not used by any NuGet packages.

GitHub repositories (1)

Showing the top 1 popular GitHub repositories that depend on DarkNet-Forms:

Repository Stars
Glumboi/GlumSak
A tool to help setting up Shaders for yuzu, ryujinx and other things!
Version Downloads Last updated