C1Theme : override theme propertie

Posted by: fsegui on 3 March 2021, 1:25 am EST

    • Post Options:
    • Link

    Posted 3 March 2021, 1:25 am EST

    Hello,

    I’m using the C1ThemeController to apply a custom theme to my application.

    In some cases, I need to override some properties (like forecolor).

    Is there some way to do it in the designer? Or do I have to do it by code?

  • Posted 3 March 2021, 4:36 pm EST

    Hi,

    Please note that the theme properties can not be changed in the program either at design time or at runtime. You can customize a theme by using the C1ThemeDesigner and then saving the theme again with the changes.

    For more info on using C1ThemeDesigner visit: https://www.grapecity.com/componentone/docs/win/online-themes/QSCreatingaCustomTheme.html#step2

    Regards.

    Avnish

  • Posted 3 March 2021, 6:59 pm EST

    Hi,

    So that means for a label that I need to change the forecolor, I have to either apply a different custom theme either not apply the theme and define all properties in the designer/code.

  • Posted 3 March 2021, 8:09 pm EST

    Hi,

    Although this is not directly possible, as a workaround you can use the following method to change any color for the specified theme for the whole application:

    private bool SetColorProperty(string themeName, string propPath, Color color)
            {
                // Get theme by name. 
                var theme = C1ThemeController.GetThemeByName(themeName, false);
                if (theme != null)
                {
                    // Get the color property at the specified path.
                    var prop = theme.Children.GetItemByPath(propPath) as ColorProp;
                    if (prop != null)
                    {
                        prop.Value = color;
                        return true;
                    }
                }
                return false;
            }
    

    You can get the path for the desired property from the C1ThemeDesigner, Please refer to the sample and image attached.

    Regards.

    Avnish

    C1ThemeCode.zip

  • Posted 3 March 2021, 8:30 pm EST

    ok thanks but that changes the color for all labels in the application.

    my need is to change the forecolor only for a few labels, not all (same for bold / not bold).

    so I’ll just set theme to “none” and apply properties in the designer.

  • Posted 4 March 2021, 3:46 pm EST

    Hi,

    If you want to apply the theme to specific labels then you can use the C1ThemeController.ApplyThemeToControlTree() method to apply specific themes to a control. You will need to use different themes for different styles. ```

    C1ThemeController.ApplyThemeToControlTree(label1, C1ThemeController.GetThemeByName(“Custom2”,true));

    Or You can apply the theme to the whole application and then change the ForeColor property of specific labels that you want with a different ForeColor.
    
    Regards.
    Avnish
  • Posted 5 March 2021, 1:48 am EST

    Hi,

    you can also implement the interface “C1.Win.C1Themes.IC1Themeable” on specific forms/user controls to :

    a) prevent the setting of theme to this control (property"AllowThemeChange")

    b) do changes after the theme was set (method “OnThemeChanged”).

    To prevent applying the theme to specific controls, you can use the method “C1ThemeController.ApplyThemeToControlTree” and provide the optional parameter “applyThemeToSubTree”: this one is called for each control and can return “false” for some controls that should not be themed.

    Best regards

    Wolfgang

  • Posted 7 March 2021, 5:07 am EST

    Thanks for your replies. I’ve made it works now!

  • Posted 22 September 2021, 2:29 pm EST

    What if you need the theme but need to change the background color of a specific panel? the theme overrides it.

  • Posted 22 September 2021, 10:38 pm EST

    Hi,

    Yes, You can change the back color of a specific control after the theme has been applied.

    You can just set the BackColor property of the panel after the Theme has been applied.

    Please refer to the sample attached.

    Regards

    Avnish

    Theme_Sep_Test.zip

Need extra support?

Upgrade your support plan and get personal unlimited phone support with our customer engagement team

Learn More

Forum Channels