question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

[WIP][API Suggestion] Introduce Win11 Dark Mode to Forms and default application settings

See original GitHub issue

Rationale

With a few new APIs which the Windows Team now made publicly available, we can start to introduce DarkMode functionality for WinForms. This is one of our most requested customer features. By introducing CsWin32 to our WinForms repo, adapting more and more Windows DarkMode Features overtime to WinForms is also comparatively easy to achieve.

This API proposal starts with a general concept for how to handle DarkMode in WinForms, and how to apply DarkMode look and feel just to a WinForms Form title bar.

image

List of new APIs

New DarkMode enum

namespace System.Windows.Forms
{
    public enum DarkMode
    {
        /// <summary>
        ///  Dark mode in the current context is not supported.
        /// </summary>
        NotSupported = 0,

        /// <summary>
        /// The setting for the current dark mode context is inherited from the parent context.
        /// </summary>
        Inherits = 1,

        /// <summary>
        /// Dark mode for the current context is enabled.
        /// </summary>
        Enabled = 2,

        /// <summary>
        /// Dark mode the current context is disabled.
        /// </summary>
        Disabled = 3
    }
}

Changed to the Application class

namespace System.Windows.Forms
{
    public sealed partial class Application
    {
            public static DarkMode DefaultDarkMode { get; } // Gets the default dark mode.
            public static DarkMode EnvironmentDarkMode { get;} // Gets if the dark mode is set for the OS or if it is not supported.

            public static bool SetDefaultDarkMode(DarkMode darkMode); // Sets the default dark mode and returns if it could be set or not.
    }
}

Changes to the Controls class

namespace System.Windows.Forms
{
    public partial class Control :
        Component,
        Ole32.IOleControl,
              .
              .
              .
    {
        public DarkMode DarkMode {get; set;} // Sets or gets the dark mode for this control. This property is ambient. The setter calls SetDarkModeCore, which can be overwritten in inherited classes
        protected virtual bool IsDarkModeEnabled {get;} // Gets a value indicating if the dark mode is actually enabled for this control
        protected virtual void SetDarkModeCore(DarkMode darkModeSetting); // The core to change the dark mode for the control. Is virtual, so an inherited class can add necessary implementations if necessary. Called by the setter of the DarkMode property.
    }
}

Changes to the Forms class

namespace System.Windows.Forms
{
    public partial class Form : ContainerControl
    {
        public Color WindowBorderColor { get; set; } // Sets or gets the Window's border color.
        public int WindowBorderThickness { get; set; } // Sets or gets the Window's border thickness.
        public Color WindowCaptionColor { get; set; } // Sets or gets the Window's caption color.
        public Color WindowCaptionTextColor { get; set; } // Sets or gets the Window's caption text color.
    }
}

Issue Analytics

  • State:open
  • Created a year ago
  • Reactions:23
  • Comments:20 (15 by maintainers)

github_iconTop GitHub Comments

3reactions
driver1998commented, Sep 20, 2022

Is the dark common control theme documented now? Last time I checked it is still undocumented. Only the dark title bar attribute is documented and public.

3reactions
Balkothcommented, Sep 12, 2022

Dark mode is easily my most wanted feature for winforms. Second would be a working PMv2 mode…

Read more comments on GitHub >

github_iconTop Results From Across the Web

How to Enable Dark Mode in Windows 11
Here's how to turn on system-wide dark mode or set color themes for specific elements in Microsoft's newest OS.
Read more >
Enable Dark Mode on Windows 11
To ENABLE dark mode on Windows 11, open Settings > Personalization > Colors, and in the "Choose your mode," select the "Dark" mode...
Read more >
How to Enable and Customize Dark Mode in Windows 11
Press Windows key + I to open Settings. From the left-hand menu, select Accessibility. From the main pane, select Contrast themes. Use the ......
Read more >
How to enable Windows 11 Dark Mode
1. Open the Settings App 2. Select "Personalization" from the sidebar to the left. 3. Select "Colors" from the options on the right....
Read more >
Enable Windows 11 Task Manager Dark Theme
Enabling Windows 11 dark mode will change the overall look and feel of the Apps including task manager and the system taskbar.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found