Table of Contents

Getting started

Install the package

ExControls is a NuGet package for .NET Framework 4.8, .NET 8 and .NET 10 on Windows:

dotnet add package ExControls

The package contains the XML documentation for IntelliSense and the extension of the Visual Studio designer, see Visual Studio designer.

Place the controls

Every extended control is named after the WinForms control with the Ex prefix: ExButton instead of Button, ExComboBox instead of ComboBox and so on. Place them from the toolbox or replace the type in the .Designer.cs file. An Ex* control behaves like the WinForms control it extends. Until a theme is applied it also looks the same, because DefaultStyle is true and the control leaves the drawing to Windows.

Use ExForm as the base class of your forms. It adds the colors of the system caption, the corners and the backdrop of Windows 11 and, with an ExTitleBar, a custom title bar:

public partial class MainForm : ExForm
{
    public MainForm() => InitializeComponent();
}

Apply a theme

ExTheme is a palette of colors. ExThemer.Apply gives it to the controls of a form: Ex* controls switch to the custom style and draw themselves in the theme colors.

var dark = new ExTheme
{
    DarkScrollBars = true,
    PanelBackColor = Color.FromArgb(43, 45, 48),
    PanelForeColor = Color.FromArgb(223, 225, 229),
    BoxBackColor = Color.FromArgb(30, 31, 34),
    BoxForeColor = Color.FromArgb(223, 225, 229),
    ButtonBackColor = Color.FromArgb(57, 59, 64),
    ButtonForeColor = Color.FromArgb(223, 225, 229),
    BorderColor = Color.FromArgb(78, 81, 87),
    HighlightBackColor = Color.FromArgb(46, 67, 110),
    HighlightForeColor = Color.White,
    MarkColor = Color.FromArgb(223, 225, 229),
    LabelForeColor = Color.FromArgb(223, 225, 229)
};

ExThemer.Apply(form.Controls, dark);
form.BackColor = dark.PanelBackColor;
form.ForeColor = dark.PanelForeColor;
form.DarkTitleBar = true;

The form is not a control of its own collection, so its colors and the dark caption are set separately. Apply the theme to the child controls first: a control that inherits a color from its parent would otherwise remember the theme color as its original one.

To return to the look of Windows, apply a theme with UseSystemStyle = true. Ex* controls switch back to DefaultStyle and restore the properties the custom style changed:

ExThemer.Apply(form.Controls, new ExTheme { UseSystemStyle = true });

Style standard controls

ExControls doesn't extend every WinForms control. DataGridView, ToolStrip, MenuStrip, Panel and others get the theme through handlers that the application registers once, before the first form:

ExThemer.Register<MenuStrip>((menu, theme) =>
{
    menu.BackColor = theme.PanelBackColor;
    menu.ForeColor = theme.PanelForeColor;
});

ExThemer.Register<Panel>((panel, theme) =>
{
    ExThemer.Apply(panel.Controls, theme);   // a container passes the theme to its child controls
    panel.BackColor = theme.PanelBackColor;
    panel.ForeColor = theme.PanelForeColor;
});

A control without a handler stays as it is and its child controls are not visited. Themes describes the handlers, restoring the system style with ExThemer.KeepDefaults and the helpers for borders and scroll bars.

Try the demo

The repository contains ExControlsTester, a WinForms program with all controls, the custom title bar, the dock manager and switching between a light and a dark theme. Clone the repository and run it:

dotnet run --project ExControlsTester