Search code examples
c#java-metro-framework

MetroStyleManager changes content's theme but not the form's theme


I have been searching everywhere and cannot find an solution.

I have a button in my MetroForm and on_click it does the following:

metroStyleManager.Theme = metroStyleManager.Theme == MetroThemeStyle.Light ? MetroThemeStyle.Dark : MetroThemeStyle.Light;

I also have a white image as the background and I have the property AllowImageInvert set to True but when I actually click the button it changes the theme of all contents in the form but not the theme of the actually form.

So I tried adding this line of code:

this.Theme = metroStyleManager.Theme;

but it always seems to be one behind.

So I click the button and the content's theme is Dark while the form theme is Light. Another click changes the content's theme to Light and the form theme changes to Dark. I have it set-up the same as the example project that works fine.

Any suggestions?

Thanks!


Solution

  • Well after hours of trial and error I finally fixed it.

    Hopefully this will help anyone else who has this issue.

    I finally added this to the end of the code:

    this.Refresh();
    

    so the final code looks like this:

    private void mtleSwitchTheme_Click(object sender, EventArgs e)
    {
        metroStyleManager.Theme = metroStyleManager.Theme == MetroThemeStyle.Light ? MetroThemeStyle.Dark : MetroThemeStyle.Light;
        this.Theme = metroStyleManager.Theme;
        this.Refresh();
    }