How to Use a Custom Theme as Default for the Entire Application
Environment
Product Version | Product | Author |
---|---|---|
2025.1.211 | Theme Tutorials for WinForms | Nadya Todorova |
Description
Telerik Presentation Framework allows users to customize any pre-defined themes that Telerik UI for WinForms offers. We provide an opportunity thanks to Visual Style Builder tool to customize the appearance of our controls to achieve the desired style for your application.
Let's pretend, we already have applied customizations and there is a custom theme already setup. For the perpose of this example, I prepared my custom Windows11CompactLightBlue theme which overrides the Windows11Compact theme. I generate variation by using Windows11CompactTheme Blending feature. I created a theme variation and use LightBlue accent color to provide my theme new fresh look. Now, it is time to start using my custom theme.
This tutorial demonstrates how to use the newly created Windows11CompactLightBlue theme as default theme in my application.
Figure 1: Using custom theme as default theme in the application:
Solution
First, it would be necessary to create theme a component. Following the instructions provided in Creating a theme component article, we should:
Add a new Class Library project to the current solution.
Add Windows11CompactLightBlue.tssp file into the Library project. It is important to set the Build Action of the .tssp to Embedded Resource.
Add a new Windows11LightBlue class to represent my theme component to the project.
namespace Windows11LightBlueClassLibrary
{
public class Windows11LightBlue : RadThemeComponentBase
{
static bool loaded;
public Windows11LightBlue()
{
ThemeRepository.RegisterTheme(this);
}
public override void Load()
{
if (!loaded || this.IsDesignMode)
{
loaded = true;
Assembly resourceAssembly = typeof(Windows11LightBlue).Assembly;
this.LoadResource(resourceAssembly, "Windows11LightBlueClassLibrary.Windows11CompactLightBlue.tssp");
}
}
public override string ThemeName
{
get { return "Windows11CompactLightBlue"; }
}
}
}
Figure 1: Here is how my ClassLibrary looks:
4.Once the Windows11LightBlueClassLibrary gets ready, we should define the custom Windows11CompactLightBlue theme as default in the entire application. This can be done inside the App.config file of our application. For more information, follow the instrucions defined here: Custom theme as Default
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<startup>
</startup>
<appSettings>
<!--define the custom Windows11CompactLightBlue for the entire application-->
<add key="TelerikWinFormsThemeName" value="Windows11CompactLightBlue" />
<add key="TelerikWinFormsThemeType" value="Windows11LightBlueClassLibrary.Windows11LightBlue"/>
<add key="TelerikWinFormsThemeAssemblyName" value="Windows11LightBlueClassLibrary, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null" />
</appSettings>
</configuration>
It is important to specify the exact TelerikWinFormsThemeAssemblyName, Version, Culture and PublicKeyToken values. These values defined in the app.config should strictly match the same values from the custom theme assembly in order to make sure that the theme should be correctly applied at design time as well as at run time.
5.Build the whole solution. Now, we can find our Windows11CompactLightBlue theme in the VS Toolbox at design time and simply drag-drop it onto RadForm as any other component. You can see the Windows11LightBlue instance in the compoenent tray. From now on, any Telerik control that you add to RadForm would have the custom theme applied automatically.
6.If you do not want to add the theme at design time, you can create an instance of the theme in the start up of the application, for example in Program.cs:
internal static class Program
{
/// <summary>
/// The main entry point for the application.
/// </summary>
[STAThread]
static void Main()
{
new Windows11LightBlueClassLibrary.Windows11LightBlue();
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);
Application.Run(new RadForm1());
}
}
We are finished! The Windows11CompactLightBlue theme is now used as default for entire application both at design time and run time.
Complete projects in .NET9 and NET Framework 48 are available in our SDK repo here.