ARTICLE

RotateTransform in WPF using VB.NET

Posted by Rohatash Kumar Articles | WPF using VB.NET January 27, 2011
In this article we will learn how to use RotateTransform in WPF using VB.NET.
Download Files:
 
Reader Level:

In this article we will learn how to use RotateTransform in WPF using VB.NET.

RotateTransform

RotateTransform 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

Taking a Image control and three Button control on the form. The form looks like this.

r1.gif

Figure 1.

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="348" 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="/WpfApplication29;component/Images/flowers-image.jpg" />

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

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

    </Grid>

</Window>

                       

Now double click on the LeftButton 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

Now double click on the RightButton and add the following code.

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

Now double click on the Same Button for old position.

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 and test it.

r2.gif

Figure 2.

Now click on the LeftButton. The image looks like this.

r3.gif

Figure 3.

Now click on the same Button. The image looks like this.

r2.gif

Figure 4.

Login to add your contents and source code to this article
share this article :
post comment
 
Nevron Diagram
Become a Sponsor
PREMIUM SPONSORS
  • ceTE software specializes in components for dynamic PDF generation and manipulation. The DynamicPDF™ product line allows you to dynamically generate PDF documents, merge PDF documents and new content to existing PDF documents from within your applications.
    The leading .NET charting control now features PDF, Flash and Silverlight export, visualization of large datasets and more. Deliver true charting functionality to your BI, Scorecard, Presentation or Scientific apps. Download evaluation now.
6 Months Free & No Setup Fees ASP.NET Hosting!
Become a Sponsor