Forms and dialogs - RobinPerris/DarkUI GitHub Wiki

WikiForms and dialogs

DarkForm inherits from Form so can be a drop-in replacement for any references you have to this within your project.

If you modify the blank Form1 class created with a fresh WinForms project you can instantly get started with a dark-themed form.

public partial class Form1 : DarkForm
{
    public Form1()
    {
        InitializeComponent();
    }
}

You should immediately see your changes in the designer.

New DarkForm

Creating a dialog

DarkDialog is a DarkForm with additional functionality which simplifies creating dialog forms.

As before with the DarkForm example, simply change any instance of Form to DarkDialog to use this class.

public partial class Form1 : DarkDialog
{
    public Form1()
    {
        InitializeComponent();
    }
}

It'll look very similar to a DarkForm except you'll now have an 'Ok' button at the bottom.

DarkDialog

This is the dialog footer, and can be changed to show a different combination of standard dialog action buttons.

Currently, the following combinations are possible.

  • Ok
  • Close
  • OkCancel
  • YesNo
  • YesNoCancel
  • AbortRetryIgnore
  • RetryCancel

You can define which buttons are shown by the dialog by modifying the DialogButtons property.

Dialog buttons

Each of the buttons are exposed to any subclasses which inherit from the DarkDialog super class, so you can modify their properties and hook in to the events as you would with any other object.

btnOk.Text = "Accept";
btnOk.Click += BtnOk_Click;

The buttons will automatically align themselves and keep everything perfectly spaced so you shouldn't have to worry about anything other than that.

Using message boxes

DarkUI offers 3 types of message boxes.

Information box.

Information box

Warning box.

Warning box

Error box.

Error box

To call each of these use the DarkMessageBox class. You can either create an object manually, or call the static methods available.

DarkMessageBox.ShowInformation("This is an information box", "Dark UI Example");
DarkMessageBox.ShowWarning("This is a warning box", "Dark UI Example");
DarkMessageBox.ShowError("This is an error box", "Dark UI Example");

DarkMessageBox is a subclass of DarkDialog so you can modify which buttons are shown in the same way.

Message box buttons

The message box is designed to properly size and position itself based on the content you pass in. As such, very long text will still look very presentable (unlike default WinForms).

Very long text