# Override Theme Settings at Run Time

This article demonstrates how to change the style for a specific element state without losing the applied style for the rest of the states.

By default, when you set a certain **RadProperty** in code, this setting will have a higher priority, called *Local*, than the setting introduced in the theme, which sets with *Style* priority (see [RadObject](https://www.telerik.com/products/winforms/documentation/telerik-presentation-framework/class-hierarchy/radobject)). As a result, if you set the **BackColor** of a button’s **FillPrimitive** in code, even though the theme defines other colors for other states (hover, pressed), these will not be applied, as the *Local* setting has higher priority than the *Style* setting. With the API discussed in this article, you will be able to override the styles defined in the theme, and set the desired property value with priority *Style*.Hence, the rest of the defined styles in the theme will still work as expected.

Here is an example. By default, **RadButton**, like most of the visual items in the UI for WinForms suite has hover state coming from the theme.

![Telerik UI for WinForms theme settings overridden at run time](https://www.telerik.com/products/winforms/documentation/assets/9e3114e4f34d7bf1a285a967bb5b23ff/tpf-override-theme-settings-at-run-time001.gif)

Consider the case in which you should change the **BackColor** for a **RadButton**. To achieve it, you will probably use the following code snippet:

 

 

```C#
            
this.radButton1.ButtonElement.ButtonFillElement.BackColor = Color.Red;
this.radButton1.ButtonElement.ButtonFillElement.GradientStyle = GradientStyles.Solid;

```

```VB.NET
Me.RadButton1.ButtonElement.ButtonFillElement.BackColor = Color.Red
Me.RadButton1.ButtonElement.ButtonFillElement.GradientStyle = GradientStyles.Solid

```



As a result, you will obtain the desired **BackColor**. However, the hover state will be lost.

![Telerik UI for WinForms control theme settings changed at run time](https://www.telerik.com/products/winforms/documentation/assets/50d14eaf2e44bc0c2969d4b08c9404d8/tpf-override-theme-settings-at-run-time002.gif)

The local value, applied to the **BackColor** property, overrides the applied style coming from the theme.

To handle this, you can use the RadItem.**SetThemeValueOverride** method by specifying the associated state.

 

 

```C#
            
this.radButton1.ButtonElement.SetThemeValueOverride(Telerik.WinControls.Primitives.FillPrimitive.BackColorProperty,
    Color.Red, "", typeof(Telerik.WinControls.Primitives.FillPrimitive));
this.radButton1.ButtonElement.SetThemeValueOverride(Telerik.WinControls.Primitives.FillPrimitive.GradientStyleProperty,
    GradientStyles.Solid, "", typeof(Telerik.WinControls.Primitives.FillPrimitive));

```

```VB.NET
Me.RadButton1.ButtonElement.SetThemeValueOverride(Telerik.WinControls.Primitives.FillPrimitive.BackColorProperty, _
                                                  Color.Red, "", GetType(Telerik.WinControls.Primitives.FillPrimitive))
Me.RadButton1.ButtonElement.SetThemeValueOverride(Telerik.WinControls.Primitives.FillPrimitive.GradientStyleProperty, _
                                                  GradientStyles.Solid, "", GetType(Telerik.WinControls.Primitives.FillPrimitive))

```

 

![Telerik UI for WinForms theme repository settings overridden at run time](https://www.telerik.com/products/winforms/documentation/assets/255d3e6cb286ea6d0b8f16a14262ed47/tpf-override-theme-settings-at-run-time003.gif)

The **GetAvailableVisualStates** method returns a list of the string representation of the applicable states for this element. These can be used as separate states or combined. When combining, use the dot notation e.g. *IsDefault.MouseOver*.

 

 

```C#
            
List<string> visualStates = this.radButton1.ButtonElement.GetAvailableVisualStates();

```

```VB.NET
Dim visualStates As List(Of String) = Me.RadButton1.ButtonElement.GetAvailableVisualStates()

```



> note Note that the normal state is represented by an empty string.

In case you need to change the hover color, you can use a similar approach:

 

 

```C#
            
this.radButton1.ButtonElement.SetThemeValueOverride(Telerik.WinControls.Primitives.FillPrimitive.BackColorProperty,
    Color.Yellow, "MouseOver", typeof(Telerik.WinControls.Primitives.FillPrimitive));
this.radButton1.ButtonElement.SetThemeValueOverride(Telerik.WinControls.Primitives.FillPrimitive.GradientStyleProperty,
    GradientStyles.Solid, "MouseOver", typeof(Telerik.WinControls.Primitives.FillPrimitive));

```

```VB.NET
Me.RadButton1.ButtonElement.SetThemeValueOverride(Telerik.WinControls.Primitives.FillPrimitive.BackColorProperty, _
                                                  Color.Yellow, "MouseOver", GetType(Telerik.WinControls.Primitives.FillPrimitive))
Me.RadButton1.ButtonElement.SetThemeValueOverride(Telerik.WinControls.Primitives.FillPrimitive.GradientStyleProperty, _
                                                  GradientStyles.Solid, "MouseOver", GetType(Telerik.WinControls.Primitives.FillPrimitive))

```

 

![Telerik UI for WinForms custom theme settings applied at run time](https://www.telerik.com/products/winforms/documentation/assets/13874ce3e405298b6e6cf4b11b81d67a/tpf-override-theme-settings-at-run-time004.gif)

Here is an example how to combine states for **RadToggleButton**

 

 

```C#
            
this.radToggleButton1.ButtonElement.SetThemeValueOverride(Telerik.WinControls.Primitives.FillPrimitive.BackColorProperty,
    Color.Aqua, "ToggleState=On.MouseOver", typeof(Telerik.WinControls.Primitives.FillPrimitive));
this.radToggleButton1.ButtonElement.SetThemeValueOverride(Telerik.WinControls.Primitives.FillPrimitive.GradientStyleProperty,
    GradientStyles.Solid, "ToggleState=On.MouseOver", typeof(Telerik.WinControls.Primitives.FillPrimitive));

```

```VB.NET
Me.RadToggleButton1.ButtonElement.SetThemeValueOverride(Telerik.WinControls.Primitives.FillPrimitive.BackColorProperty, _
                                                        Color.Aqua, "ToggleState=On.MouseOver", GetType(Telerik.WinControls.Primitives.FillPrimitive))
Me.RadToggleButton1.ButtonElement.SetThemeValueOverride(Telerik.WinControls.Primitives.FillPrimitive.GradientStyleProperty, _
                                                        GradientStyles.Solid, "ToggleState=On.MouseOver", GetType(Telerik.WinControls.Primitives.FillPrimitive))

```

 

![Telerik UI for WinForms runtime theme changes displayed in a control](https://www.telerik.com/products/winforms/documentation/assets/3251754ab39803ed2a218038eea74a7a/tpf-override-theme-settings-at-run-time005.gif)

> note You can use the **ResetThemeValueOverrides** method if you need to reset the applied style for a specific state of the element.

## See Also

* [Inherit themes from RadControls derivatives](https://www.telerik.com/products/winforms/documentation/telerik-presentation-framework/inherit-themes-from-radcontrols-derivatives)
