开发者

How do I switch themes in Telerik WinForms?

How do I tell Telerik for WinForms which of its themes to use?

I created a new WinForms project and dropped a RadPageView on the form, but there's a 5-pixel margin of dead space all the way around, the tabs are almost twice as tall as they need to be, and everything is shiny and blue. Even apart from the wasted space, all this blue stuff would look horribly out of place in our app. I just want a standard Windows look, and I'm assuming that the way to accomplish that is to select a different, less-blue, less-shiny theme. (Or is there another way?)

Here's what I've tried:

  • I tried setting EnableTheming to False, but then the tabs have no borders at all, so there's absolutely no indication of where to click or which tab is active -- no good at all.
  • I can drop down the ThemeName property in the Property Grid, but the only options are "Reset" and "ControlDefault". Neither setting does anything (even with EnableTheming set back to True).
  • There are a bunch of Theme classes in the Toolbox (AquaTheme, BreezeTheme, etc.), but adding those to my form doesn't make any difference. I thought they might appear in the ThemeName dropdown, but they don't.
  • I tried dropping a RadThemeManager on my form, but it only has a LoadedThemes collection, which is empty. I can add things to it, but that just adds a ThemeSource, and setting one of those up seems to involve browsing to a file, and I don't have any theme files to browse to.
  • There's a ThemeClassName property on the RadPageView, but it's just a string (defaults to Telerik.WinControls.UI.RadPageView) and 开发者_开发百科I have no idea what I might change it to, or how it even relates to themes.

This is ridiculous. All I want is a tab control that looks like a tab control! How can I do that?


The best way to accomplish this application-wide would be to use the ThemeResolutionService. You'll need to drag out one of the themes from the toolbox first. For example, if you add the Windows7Theme component to your form, you'd apply the theme using the following.

private void Form1_Load(object sender, EventArgs e)
{
    ThemeResolutionService.ApplicationThemeName = "Windows7";
}

I recommend checking out this video related to themes as well: http://tv.telerik.com/watch/winforms/visualstylebuilder/changing-themes-at-run-time-with-radcontrols-winforms


I'm currently working on a Winform/Telerik application. It's a MDI application.

First, I added in the References of my Project the Telerik.Wincontrols.Themes.Breeze dll, then in the constructor of my main form, here is what I did :

    private fMain()
    {
        InitializeComponent();

        ThemeResolutionService.ApplicationThemeName = "Breeze"; 
        RadGridLocalizationProvider.CurrentProvider = new FrenchRadGridLocalizationProvider();
    }

I also added the French RadGridLocalizationProvider.

And it works, all my RadDataGridViews are in French and have the Breeze theme.

Even if the Form used is not a Telerik one, which is my case, I don't use RadForm !


To make loading of themes dynamic, I did following:

private void LoadTheme()
{

        var themefiles = Directory.GetFiles(System.Windows.Forms.Application.StartupPath, "Telerik.WinControls.Themes.*.dll");

        foreach (var theme in themefiles)
        {
            var themeAssembly = Assembly.LoadFile(theme);
            var themeType = themeAssembly.GetTypes().Where(t => typeof(RadThemeComponentBase).IsAssignableFrom(t)).FirstOrDefault();
            if (themeType != null)
            {
                RadThemeComponentBase themeObject = (RadThemeComponentBase)Activator.CreateInstance(themeType);
                if (themeObject != null)
                {
                    themeObject.Load();
                }
            }
        }
        var themeList = ThemeRepository.AvailableThemeNames.ToList();                
            themeDropDown.DataSource = themeList;
}

private void ThemeDropDown_SelectedIndexChanged(object sender, Telerik.WinControls.UI.Data.PositionChangedEventArgs e)
{
            string strTheme = themeDropDown.Text;
            Theme theme = ThemeResolutionService.GetTheme(strTheme);
            if (theme != null)
            {
                    ThemeResolutionService.ApplicationThemeName = theme.Name;    
            }
}

I was able to achieve completely dynamic theme changing experience. In case Telerik release or updates themes in future, the only thing required will be to add the theme dlls in the application folder.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜