PawLab.WindowsTheme 1.0.1

dotnet add package PawLab.WindowsTheme --version 1.0.1
                    
NuGet\Install-Package PawLab.WindowsTheme -Version 1.0.1
                    
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="PawLab.WindowsTheme" Version="1.0.1" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="PawLab.WindowsTheme" Version="1.0.1" />
                    
Directory.Packages.props
<PackageReference Include="PawLab.WindowsTheme" />
                    
Project file
For projects that support Central Package Management (CPM), copy this XML node into the solution Directory.Packages.props file to version the package.
paket add PawLab.WindowsTheme --version 1.0.1
                    
#r "nuget: PawLab.WindowsTheme, 1.0.1"
                    
#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.
#:package PawLab.WindowsTheme@1.0.1
                    
#:package directive can be used in C# file-based apps starting in .NET 10 preview 4. Copy this into a .cs file before any lines of code to reference the package.
#addin nuget:?package=PawLab.WindowsTheme&version=1.0.1
                    
Install as a Cake Addin
#tool nuget:?package=PawLab.WindowsTheme&version=1.0.1
                    
Install as a Cake Tool

WindowsTheme

A lightweight .NET library for managing Windows theme settings, including dark/light mode detection, window title bar color customization, and per-window theme application. Designed for Windows 10 and Windows 11 (with full DWM API support).

License

Copyright 2026 xionglongztz/PawLaboratory

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

Features

  • Detect whether the system or application is set to dark mode via registry queries.
  • Set custom title bar and border colors on Windows 11 (and newer) using DWM attributes.
  • Automatically choose title bar text color (black or white) based on background brightness.
  • Apply dark or light theme to a specific window (including immersive dark mode and menu theme flushing).
  • Simple, static API �C no instantiation required.

Installation

Add the source files to your project, or reference the compiled assembly. The library has no external dependencies beyond the .NET Framework / .NET Core / .NET 5+ runtime that supports System.Runtime.InteropServices and Microsoft.Win32.

Usage Examples

VB.NET

Imports PawLab.WindowsTheme

' Check current system dark mode
Dim isSystemDark As Boolean = ThemeService.IsSystemDarkMode()
Console.WriteLine($"System dark mode: {isSystemDark}")

' Check app (modern UI) dark mode
Dim isAppDark As Boolean = ThemeService.IsAppDarkMode()
Console.WriteLine($"App dark mode: {isAppDark}")

' Set title bar color for a window (e.g., main form handle)
Dim hwnd As IntPtr = Me.Handle   ' or any window handle
ThemeService.SetTitleBarColor(hwnd, 30, 144, 255)   ' Dodger blue

' Apply dark theme to the window
ThemeService.SetWindowTheme(hwnd, True)

C#

using PawLab.WindowsTheme;

// Check current system dark mode
bool isSystemDark = ThemeService.IsSystemDarkMode();
Console.WriteLine($"System dark mode: {isSystemDark}");

// Check app (modern UI) dark mode
bool isAppDark = ThemeService.IsAppDarkMode();
Console.WriteLine($"App dark mode: {isAppDark}");

// Set title bar color for a window (e.g., main form handle)
IntPtr hwnd = this.Handle;   // or any window handle
ThemeService.SetTitleBarColor(hwnd, 30, 144, 255);   // Dodger blue

// Apply dark theme to the window
ThemeService.SetWindowTheme(hwnd, true);

API Reference

ThemeService (Public Static Class)

IsAppDarkMode() As Boolean

Returns True if the current user setting for application theme (AppsUseLightTheme) is dark (value = 0), otherwise False.

IsSystemDarkMode() As Boolean

Returns True if the current user setting for system theme (SystemUsesLightTheme) is dark (value = 0), otherwise False.

SetTitleBarColor(hwnd As IntPtr, r As Byte, g As Byte, b As Byte)

Sets the title bar and border background color for the given window handle. The text color is automatically chosen (black on light background, white on dark background) based on the perceived brightness.
Note: This feature is fully effective only on Windows 11 and later.

SetWindowTheme(hwnd As IntPtr, Optional isDarkMode As Boolean = False)

Applies immersive dark or light mode to the specified window. Also updates menu themes and flushes them to take effect immediately.

  • isDarkMode = True �� force dark mode
  • isDarkMode = False (default) �� force light mode

Internal Helper Classes (not intended for direct use)

  • WinAPI �C P/Invoke declarations for DwmSetWindowAttribute, SetPreferredAppMode, FlushMenuThemes, and related enums.
  • Utilities �C Color conversion (RGBToCOLORREF) and brightness calculation (GetForeColor).

Requirements

  • Windows 10 or later (some features like title bar color are Windows 11 only).
  • .NET Framework 4.5+ or .NET Core/5/6/7/8.

Remarks

  • Registry keys are read from HKEY_CURRENT_USER\SOFTWARE\Microsoft\Windows\CurrentVersion\Themes\Personalize.
  • The library uses DwmSetWindowAttribute with attribute IDs (e.g., UseImmersiveDarkMode = 20, CaptionColor, BorderColor, TextColor).
  • Title bar color changes may not be visible if the window is using custom chrome or if the system theme overrides certain settings.

Contributing

Contributions are welcome. Please open an issue or pull request on the official repository.

License

Apache 2.0 �C see the LICENSE file for details.

Product Compatible and additional computed target framework versions.
.NET net6.0-windows7.0 is compatible.  net7.0-windows was computed.  net8.0-windows was computed.  net8.0-windows7.0 is compatible.  net9.0-windows was computed.  net10.0-windows was computed. 
.NET Framework net462 is compatible.  net463 was computed.  net47 was computed.  net471 was computed.  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.
  • .NETFramework 4.6.2

    • No dependencies.
  • .NETFramework 4.7.2

    • No dependencies.
  • net6.0-windows7.0

    • No dependencies.
  • net8.0-windows7.0

    • No dependencies.

NuGet packages

This package is not used by any NuGet packages.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last Updated
1.0.1 94 9/6/2026
1.0.0 99 9/6/2026