How can I manually apply style to a control? (WinForms)

1 Answer 117 Views
Themes and Visual Style Builder
Wojciech
Top achievements
Rank 1
Wojciech asked on 29 Jun 2021, 09:46 AM

I have a button and I'd like it to look the same way as the title bar close button does.

How can I apply a specific style to a control?

The only thing I tried is to access theme information, but it is really complicated as there are multiple levels of nesting and derivation of settings etc. I think, that there should be easier way to do this.

      var theme = Telerik.WinControls.ThemeResolutionService.GetTheme(TelerikSkinAdapter.GetThemeName("MySkin"));
      foreach (var group in theme.StyleGroups)
        foreach (var registration in group.Registrations)
          System.Diagnostics.Debug.WriteLine($"{registration.ControlName} {registration.ControlType} {registration.ElementName} {registration.ElementType}");

1 Answer, 1 is accepted

Sort by
0
Nadya | Tech Support Engineer
Telerik team
answered on 29 Jun 2021, 03:30 PM

Hello, Wojciech,

According to the provided information, it is not clear which controls you have on your form and how are they styled. If I understand you correctly you want all the controls on the form to have the same look and feel. In this case, you can use one theme for all controls that you have. You can use the ThemeResolutionService class and specify the ApplicationThemeNamehttps://docs.telerik.com/devtools/winforms/styling-and-appearance/using-a-default-theme-for-the-entire-application. Note, the ApplicationThemeName property affects the whole application this needs to be set just once.

If you are working at design time you can change the theme of the form and apply it to all controls on the form. All you need to do is right-click the form and choose "Apply current form's theme to controls"https://docs.telerik.com/devtools/winforms/styling-and-appearance/using-default-themes#applying-theme-to-all-controls-in-the-current-form 

Alternatively, you can set the ThemeName property of the controls. Feel free to use the approach that is most suitable for your scenario.

I hope this information is useful. Please let me know if I can assist you further.

Regards,
Nadya
Progress Telerik

Virtual Classroom, the free self-paced technical training that gets you up to speed with Telerik and Kendo UI products quickly just got a fresh new look + new and improved content including a brand new Blazor course! Check it out at https://learn.telerik.com/.

Tags
Themes and Visual Style Builder
Asked by
Wojciech
Top achievements
Rank 1
Answers by
Nadya | Tech Support Engineer
Telerik team
Share this question
or