RotateTransform WPF in VB.NET

Here we will see that how to rotate an image to a certain angle around a central point in WPF using XAML.
  • 7550
 

Here we will see that how to rotate an image to a certain angle around a central point in WPF using XAML.

Rotate Transform

Rotate Transform is used for the process of rotating an element to a certain angle around a central point. The below example shows image rotating according to a angle.

Example

Creating a Image control and three Button control on the window form.

XAML code

<Window x:Class="MainWindow"

    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"

    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"

    Title="MainWindow" Height="350" Width="525">

   <Grid>

        <Button Content="LeftRotate" Height="23" HorizontalAlignment="Left" Margin="386,12,0,0" Name="Button1" VerticalAlignment="Top" Width="75" />

        <Image Height="150" HorizontalAlignment="Left" Margin="134,40,0,0" Name="Image1" Stretch="Fill" VerticalAlignment="Top" Width="200" Source="/WpfApplication76;component/Images/image1.jpg.gif" />

        <Button Content="RightRotate" Height="23" HorizontalAlignment="Left" Margin="386,49,0,0" Name="Button2" VerticalAlignment="Top" Width="75" />

        <Button Content="Same" Height="23" HorizontalAlignment="Right" Margin="0,87,42,0" Name="Button3" VerticalAlignment="Top" Width="75" />

    </Grid>

</Window>

 

The window form looks like this.

rt1.gif

Figure1.gif

Now double click on the each Button control and add the following code.

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.Windows.RoutedEventArgs) Handles Button1.Click

        Dim rotateTransform1 As New RotateTransform()

        rotateTransform1.Angle = 30

        Image1.RenderTransform = rotateTransform1

    End Sub

 

    Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.Windows.RoutedEventArgs) Handles Button2.Click

        Dim rotateTransform1 As New RotateTransform()

        rotateTransform1.Angle = 60

        Image1.RenderTransform = rotateTransform1

    End Sub

 

    Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.Windows.RoutedEventArgs) Handles Button3.Click

        Dim rotateTransform1 As New RotateTransform()

        Image1.RenderTransform = rotateTransform1

    End Sub

 

Now run the application.

rt2.gif

Figure2.gif

Now click on the LeftRotate or RightRotate Button and test it.

rt3.gif

Figure3.gif

Now click on the same to the old position.

rt4.gif

Figure4.gif

Categories

More Articles

© 2020 DotNetHeaven. All rights reserved.