Table of Contents

ExMessageBox

ExMessageBox shows a message box in the colors of the application. The static Show methods take the same arguments as MessageBox.Show, so replacing the class name is enough to give the message boxes of an application a dark theme.

Showing a message

var result = ExMessageBox.Show(this, "Do you want to save the changes to Untitled.txt?", "ExControls",
    MessageBoxButtons.YesNoCancel, MessageBoxIcon.Question);

The overloads with a help file and HelpNavigator show a Help button like MessageBox. Every overload takes an optional countdown in seconds, after which the message box closes itself. An instance gives more control:

var message = new ExMessageBox(this, "The connection was lost.", "ExControls")
{
    Buttons = MessageBoxButtons.RetryCancel,
    Icon = MessageBoxIcon.Warning,
    Countdown = 30   // closes itself after 30 seconds
};
message.HelpRequested += (_, _) => OpenHelp();
var result = message.Show();

Options, DefaultButton, ShowHelp and Form (the ExMessageBoxForm of the message) are available on the instance as well.

Style

ExMessageBox.Style is shared by all message boxes. Set it when the theme of the application changes:

ExMessageBox.Style = theme.UseSystemStyle ? new ExMessageBoxStyle() : new ExMessageBoxStyle
{
    DefaultStyle = false,
    UseDarkTitleBar = isDark,
    BackColor = theme.BoxBackColor,
    ForeColor = theme.BoxForeColor,
    FooterBackColor = theme.PanelBackColor,
    ButtonBackColor = theme.ButtonBackColor,
    ButtonForeColor = theme.ButtonForeColor,
    ButtonBorderColor = theme.BorderColor,
    ButtonMouseOverColor = theme.HighlightBackColor,
    ButtonMouseDownColor = theme.HighlightBackColor
};

LabelFont and ButtonsFont change the fonts, ButtonBorderSize the border of the buttons. A property left null keeps the default.

Texts and icons

The texts of the buttons are static properties (ButtonOKText, ButtonCancelText, ButtonYesText, ButtonNoText, ButtonAbortText, ButtonRetryText, ButtonIgnoreText, ButtonHelpText). By default they come from the resources of Windows in its display language, like the buttons of MessageBox.

The icons are the stock icons of Windows. ExMessageBox.IconProvider replaces them, for example by icons of the application that fit a dark theme:

ExMessageBox.IconProvider = (icon, control) => icon switch
{
    MessageBoxIcon.Error => Icons.Error32,
    MessageBoxIcon.Warning => Icons.Warning32,
    _ => null   // the stock icon
};

The message box doesn't dispose the image, the application owns it.

API