Skip to content

nemethviktor/WinFormsDarkThemerNinja

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

7 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Welcome to WinFormsDarkThemerNinja!

WinFormsDarkThemerNinja is a simple tool for developers to apply (dark) theming for most of the core Windows Controls. It also supports MessageBox theming, with and without DialogResult return. Actually you can set any colour you want, it doesn't have to be "dark" per se.

The current release is a beta but it generally works. I'm open to ideas and queries.

Note please that WinForms doesn't natively support Dark Mode and this is on a best-effort basis. It'll never likely look as good as WinUI3 interfaces do but it's totally passable.

The NuGet Package NuGet NuGet

PM> Install-Package WinFormsDarkThemerNinja.Official

Supported .NET versions

  • .NET Framework 4.6.2 or above
  • .NET Core 3.1
  • .NET 5.0 or above

Usage

You need to reference the DLL file. The main method you'll be using is ApplyThemeToControl, which takes Control and an enum (WinFormsDarkThemerNinja.Themer.ThemeStyle.Custom or WinFormsDarkThemerNinja.Themer.ThemeStyle.Default) [defaults to Custom].

using Themer = WinFormsDarkThemerNinja.Themer;

private void Form1_Load(object sender, System.EventArgs e)
{
    Themer.DarkColor = Color.Yellow; // optional; see below in readme for options.
 
    // themeStyle is optional. here's a way to demo how/why it may be useful.
    Themer.ApplyThemeToControl(
        control: this,
        themeStyle: HelperVariables.UserSettingUseDarkMode ?
            Themer.ThemeStyle.Custom :
            Themer.ThemeStyle.Default
        );
}

Things should look generally like so when using defaults:

alt text

Parameters

All of the below are optional. For ApplyThemeToControl you can choose to have WinFormsDarkThemerNinja.Themer.ThemeStyle.Custom or WinFormsDarkThemerNinja.Themer.ThemeStyle.Default. Default will essentially do nothing. You can provide your own set of colours (e.g. the yellow above). The following are customisable:

  • DarkColor (default #1C1D23)
  • LessDarkColor (default #2B2D31; note this is the background colour for ListViews.
  • TextColor (default #FFFFFF)
  • BorderColor (default #BAB9B9)

Bools

  • DoNotConvertImagesToGrayscale (default false)

There is an automatic conversion of Buttons' (Background) Images and those of ToolStripButtons'. If you don't want this, set DoNotConvertImagesToGrayscale to true. (ie. Themer.DoNotConvertImagesToGrayscale = true;)

MessageBoxes and DialogResults

As for MessageBoxes you can do:

using Themer = WinFormsDarkThemerNinja.Themer;
Themer.ShowMessageBox(message: "hello");

alt text

or

using Themer = WinFormsDarkThemerNinja.Themer;
_ = Themer.ShowMessageBoxWithResult(
                message: "hello?",
                buttons: MessageBoxButtons.YesNo
                );

alt text

MessageBox Parameters

ShowMessageBox and ShowMessageBoxWithResult take the standard params so you can just replace the normal Messagebox.Show() logic. The actual layout is:

public static void ShowMessageBox(
    string message,
    string caption = "",
    MessageBoxButtons buttons = MessageBoxButtons.OK,
    MessageBoxIcon icon = MessageBoxIcon.None,
    ThemeStyle themeStyle = ThemeStyle.Custom
    )

For the buttons and icon these are standard, you can use any MessageBoxButtons and MessageBoxIcon.

Caveats/Issues

Most things work, but...

  • If you want your Form to have a dark header you need to add a manifest file to your application. You can do this via Visual Studio. See further down for details.
  • A disabled Control's text colour is always a fixed ControlDark. That cannot be overriden without waylaying the Paint event but that causes a lot of other issues so I'm not doing it.
  • A disabled ListView always has white background.
    • I used a very hacky solution to get around it from here, if it doesn't work okay, shout. I changed it to work off the basis of Size, not ClientSize.
  • ListView's ContextMenuStrips should work. The one place I tested it worked.
  • ListViewColumnHeader may or may not work. I tested it in two scenarios, one worked, the other didn't but I haven't managed to figure why.
  • DateTimePicker is also not getting the theming instructions. I think they actually cannot be overriden without having an entirely different class.
  • ToolTips' themeing also don't seem to work.
  • The CustomMessageBox DPI scaling is should be okay but if not, shout. If you have good ideas how to get around mis-sizing, also shout.

The Manifest file

I don't want to include a whole file because you may have your own things to use but in the manifest file ensure you have the following block (replace the original obviously)

 <compatibility xmlns="urn:schemas-microsoft-com:compatibility.v1">
    <application>
      <!-- A list of the Windows versions that this application has been tested on
           and is designed to work with. Uncomment the appropriate elements
           and Windows will automatically select the most compatible environment. -->

      
            <!-- Windows 10 and Windows 11 -->
            <supportedOS Id="{8e0f7a12-bfb3-4fe8-b9a5-48fd50a15a9a}"/>
            <!-- Windows 8.1 -->
            <supportedOS Id="{1f676c76-80e1-4239-95bb-83d0f6d0da78}"/>
            <!-- Windows 8 -->
            <supportedOS Id="{4a2f28e3-53b9-4441-ba9c-d69d4a4a6e38}"/>
            <!-- Windows 7 -->
            <supportedOS Id="{35138b9a-5d96-4fbd-8e2d-a2440225f93a}"/>
            <!-- Windows Vista -->
            <!-- <supportedOS Id="{e2011457-1546-43c5-a5fe-008deee3d3f0}"/> -->
  

    </application>
  </compatibility>

Further notes

As mentioned above this only supports the normal WinForms Controls. Things like DevExpress etc aren't supported, sorry.

If you need some guidance on DevExpress theming, check out this blog post.

If you need guidance for other commercial libraries' theming, sorry, I can't help.

About

WinFormsDarkThemerNinja is a class library that allows .NET developers to add themeing to WinForms Controls.

Topics

Resources

License

Stars

Watchers

Forks

Packages

 
 
 

Contributors

Languages