# Animations

Using the [Telerik Presentation Framework](https://www.telerik.com/products/winforms/documentation/telerik-presentation-framework/overview/overview) you can animate almost any element property. To achieve this you should use the **AnimatedPropertySetting** class. The class constructors takes five arguments:

* The first argument of the **AnimatedPropertySetting** is the **RadProperty** to animate.

* The second one is the **start value**.

* Next is the **end value**.

* The fourth argument takes the **number of frames**.

* And the last argument is the **time interval between frames** in milliseconds

## Animate opacity

The following example animates the **Opacity** property of the RadButton's FillPrimitive, changing it from 1 to 0 (full transparent) and vice versa:

![Telerik UI for WinForms Telerik Presentation Framework opacity animation](https://www.telerik.com/products/winforms/documentation/assets/1fa4e683be9e1788099fc1232aabb743/tpf-animations001.gif)

#### Animate button's Opacity property

 

 

```C#
private void btnAnimateOpacity_Click(object sender, EventArgs e)
{
    if (btnAnimateOpacity.ButtonElement.ButtonFillElement.Opacity == 0)
    {
        AnimatedPropertySetting setting = new AnimatedPropertySetting(FillPrimitive.OpacityProperty, 0.0, 1.0, 20, 20);
        setting.ApplyValue(btnAnimateOpacity.ButtonElement.ButtonFillElement);
    }
    else
    {
        AnimatedPropertySetting setting = new AnimatedPropertySetting(FillPrimitive.OpacityProperty, 1.0, 0.0, 20, 20);
        setting.ApplyValue(btnAnimateOpacity.ButtonElement.ButtonFillElement);
    }
}

```

```VB.NET
Private Sub btnAnimateOpacity_Click(sender As System.Object, e As System.EventArgs) Handles btnAnimateOpacity.Click
    If btnAnimateOpacity.ButtonElement.ButtonFillElement.Opacity = 0 Then
        Dim setting As New AnimatedPropertySetting(FillPrimitive.OpacityProperty, 0.0, 1.0, 20, 20)
        setting.ApplyValue(btnAnimateOpacity.ButtonElement.ButtonFillElement)
    Else
        Dim setting As New AnimatedPropertySetting(FillPrimitive.OpacityProperty, 1.0, 0.0, 20, 20)
        setting.ApplyValue(btnAnimateOpacity.ButtonElement.ButtonFillElement)
    End If
End Sub

```

 

## Animate margin

Here is how to animate the **Margin** property of the RadButton's FillPrimitive:

![Telerik UI for WinForms Telerik Presentation Framework margin animation](https://www.telerik.com/products/winforms/documentation/assets/e9d8c4bc8972fb3171fb4d42926f394f/tpf-animations002.gif)

#### Animate button's Margin property

 

 

```C#
private void btnAnimateMargin_Click(object sender, EventArgs e)
{
    AnimatedPropertySetting setting2 = new AnimatedPropertySetting();
    setting2.Property = RadElement.MarginProperty;
    setting2.StartValue = new Padding(0);
    setting2.EndValue = new Padding(10);
    setting2.NumFrames = 14;
    setting2.Interval = 30;
    setting2.ApplyValue(btnAnimateMargin.ButtonElement);
}

```

```VB.NET
Private Sub btnAnimateMargin_Click(sender As System.Object, e As System.EventArgs) Handles btnAnimateMargin.Click
    Dim setting2 As New AnimatedPropertySetting()
    setting2.Property = RadElement.MarginProperty
    setting2.StartValue = New Windows.Forms.Padding(0)
    setting2.EndValue = New Windows.Forms.Padding(10)
    setting2.NumFrames = 14
    setting2.Interval = 30
    setting2.ApplyValue(btnAnimateMargin.ButtonElement)
End Sub

```

 

## Animate bounds

You can also animate the **Bounds** property of a control. Here is how to create a fly-out animation with RadPanel:

![Telerik UI for WinForms Telerik Presentation Framework bounds animation](https://www.telerik.com/products/winforms/documentation/assets/68c9bcfffa4db17d7cef675d547e8458/tpf-animations003.gif)

#### Animate button's Bounds property

 

 

```C#
private void radButton1_Click(object sender, EventArgs e)
{
    RadPanel panel = new RadPanel();
    panel.BackColor = Color.Yellow;
    panel.AutoSize = true;
    panel.RootElement.StretchVertically = true;
    panel.RootElement.StretchHorizontally = true;
    panel.Location = new Point(10, 10);
    panel.Size = new Size(200, 1);
    panel.Text = "I am RadPanel";
    this.Controls.Add(panel);
    AnimatedPropertySetting setting = new AnimatedPropertySetting();
    setting.Property = RadElement.BoundsProperty;
    setting.StartValue = new Rectangle(0, 0, 200, 1);
    setting.EndValue = new Rectangle(0, 0, 200, 100);
    setting.Interval = 30;
    setting.NumFrames = 10;
    setting.ApplyValue(panel.RootElement);
}

```

```VB.NET
Private Sub RadButton1_Click(sender As System.Object, e As System.EventArgs) Handles RadButton1.Click
    Dim panel As New RadPanel()
    panel.BackColor = Color.Yellow
    panel.AutoSize = True
    panel.RootElement.StretchVertically = True
    panel.RootElement.StretchHorizontally = True
    panel.Location = New Point(10, 10)
    panel.Size = New Size(200, 1)
    panel.Text = "I am RadPanel"
    Me.Controls.Add(panel)
    Dim setting As New AnimatedPropertySetting()
    setting.[Property] = RadElement.BoundsProperty
    setting.StartValue = New Rectangle(0, 0, 200, 1)
    setting.EndValue = New Rectangle(0, 0, 200, 100)
    setting.Interval = 30
    setting.NumFrames = 10
    setting.ApplyValue(panel.RootElement)
End Sub

```



## See Also

* [Dependency Properties](https://www.telerik.com/products/winforms/documentation/telerik-presentation-framework/dependency-properties)

* [Handling User Input](https://www.telerik.com/products/winforms/documentation/telerik-presentation-framework/handling-user-input)

* [HTML-like Text Formatting](https://www.telerik.com/products/winforms/documentation/telerik-presentation-framework/html-like-text-formatting)

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