Sign in to follow this  
toe_head2001

[Guide] Dark Theme support for custom ConfigDialog

Recommended Posts

Adding support for the Dark Theme is very easy, and only takes a few minutes.

 

The first step is to set the UseAppThemeColors property in your EffectConfigDialog to true.

This can be done use the Properties pane in Visual Studio:

UseThemeColors.png

 

This will automatically set the ForeColor and BackColor of your Form based on the active PDN theme, and most of the child controls will simply inherit those color values.

 

There are some special cases though.

 

For Buttons (ex: OK, Cancel), you'll want to set their FlatStyle property to System.

FlatStyle.png

 

 

For TextBoxes and NumericUpDowns, you'll need to set the colors manually.

For example:

myTextBox.ForeColor = this.ForeColor;
myTextBox.BackColor = this.BackColor;

or if you have many in your form, you may want to use a foreach loop:

public MyConfigDialog()
{
    InitializeComponent();

    foreach (Control control in this.Controls)
    {
        if (control is TextBox || control is NumericUpDown)
        {
            control.ForeColor = this.ForeColor;
            control.BackColor = this.BackColor;
        }
    }
}

 

Share this post


Link to post
Share on other sites
3 hours ago, toe_head2001 said:

For Buttons (ex: OK, Cancel), you'll want to set their FlatStyle property to System.

 

That is less work than resetting the button colors when using FlatStyle.Standard.

 

If your dialog uses a LinkLabel you can use the following code to change the link color.

if (control is LinkLabel link)
{
    if (this.ForeColor != Control.DefaultForeColor)
    {
        link.LinkColor = this.ForeColor;
    }
    else
    {
        // If the control is using the default foreground color set the link color
        // to Color.Empty so the LinkLabel will use its default colors.
        link.LinkColor = Color.Empty;
    }
}

 

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this