New to Telerik UI for WinForms? Download free 30-day trial

Creating a theme component

This article demonstrates how to isolate a theme in a separate class library project. This class library project is actually the theme component, which you can later use in your main project. This approach greatly simplifies the way of adding and removing themes to your project and helps in displaying the themes in design-time.

  1. Add a new Class Library project to your current solution.

  2. Add your theme files and their Build Action to Embedded Resource.

  3. Add a new class to represent your theme component to the project:

Creating custom theme component

public class CustomTheme : RadThemeComponentBase
{
    static bool loaded;
    public CustomTheme()
    {
        ThemeRepository.RegisterTheme(this);
    }
    public override void Load()
    {
        if (!loaded || this.IsDesignMode)
        {
            loaded = true;
            Assembly resourceAssembly = typeof(CustomTheme).Assembly;
            this.LoadResource(resourceAssembly, "ProjectDefaultNamespace.ContainingFolderName.CustomTheme.tssp");
        }
    }
    public override string ThemeName
    {
        get { return "CustomTheme"; }
    }
}

Please note that your class should inherit RadThemeComponentBase. As to the path string, it is constructed as follows: "ProjectDefaultNamespace.ContainingFolderName.CustomTheme.tssp" . The ContainingFolderName is only needed if the tssp file is in folder in the project structure (C# only). Regarding VB.NET, even if the theme file is in a folder, you should not include the folder name in the path string.

When you compile the project, you will be able to drag this component to the forms in all the projects in you solution which will load the corresponding theme, both runtime and design time.