ARTICLE

RadioButton control in WPF using VB.NET

Posted by Rohatash Kumar Articles | WPF using VB.NET January 03, 2011
In this article we will learn how to use RadioButton control of WPF. I also explained how to rotate image in WPF.
 
Reader Level:

In this article we will learn how to use RadioButton control of WPF. I also explained how to rotate image in WPF.

RadioButton Control

RadioButton control are mostly used together in a group but one is selected at a time.

Properties - This control has the following properties.

r6.gif

Figure 1.

For example:

Drag and drop a image control, five RadioButton control and one Button control from the Toolbox on the Form and select an image from the source property of the Image control. RadioButtons named left, right, up, Down and same. Button named rotate.The form looks like this.

r5.gif

Figure 2.

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>

        <RadioButton Content="Left" Height="16" HorizontalAlignment="Left" Margin="12,208,0,0" Name="Rdbtnleft" VerticalAlignment="Top" />

 

        <RadioButton Content="Right" Height="16" HorizontalAlignment="Left" Margin="112,208,0,0" Name="Rdbtnright" VerticalAlignment="Top" />

 

        <RadioButton Content="Up" Height="16" HorizontalAlignment="Left" Margin="206,208,0,0" Name="Rdbtnup" VerticalAlignment="Top" />

 

        <RadioButton Content="Down" Height="16" HorizontalAlignment="Left" Margin="300,208,0,0" Name="Rdbtndown" VerticalAlignment="Top" />

 

        <Image Height="150" HorizontalAlignment="Left" Margin="124,12,0,0" Name="Image1" Stretch="Fill" VerticalAlignment="Top" Width="200" Source="/WpfApplication6;component/Images/imagec26.jpg" />

 

        <Button Content="Rotate" Height="23" HorizontalAlignment="Left" Margin="124,242,0,0" Name="Button1" VerticalAlignment="Top" Width="97" />

 

        <RadioButton Content="Same" Height="16" HorizontalAlignment="Left" Margin="300,245,0,0" Name="Rdbtnsame" VerticalAlignment="Top" />

       

    </Grid>

</Window>

Rotation of image is being performed by RotateTransform class.

Dim rotate As New RotateTransform()

In click event of Button we are checking radio button's isChecked property. If IsChecked is true for a radio button it means that radio button is selected.

Now double click on the Button named Rotate of the designing form and add the following code.

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

        Dim rotate As New RotateTransform()

        If Rdbtnleft.IsChecked = True Then             ' Left rotate

            rotate.Angle = 30

            Image1.RenderTransform = rotate

        ElseIf  Rdbtnright.IsChecked = True Then       ' right rotate

            rotate.Angle = 45

            Image1.RenderTransform = rotate

        ElseIf Rdbtnup.IsChecked = True Then           ' up rotate    

            rotate.Angle = 60

            Image1.RenderTransform = rotate                  

 

        ElseIf Rdbtndown.IsChecked = True              'Down rotate

            rotate.Angle = 90

            Image1.RenderTransform = rotate

        Else

            Rdbtnsame.IsChecked = True                   ' for same position

            Image1.RenderTransform = rotate

        End If

    End Sub

Now save and run the application.

r1.gif

Figure 3.

Now select Up RadioButton and click on the rotate Button.

r2.gif

Figure 4.

Now to take old position select same RadioButton and click on the rotate Button.

r3.gif

Figure 5.

Now select Down RadioButton and click on the rotate Button.

r4.gif

Figure 6.

Login to add your contents and source code to this article
share this article :
post comment
 
Become a Sponsor
PREMIUM SPONSORS
  • Finally – a virtual platform that delivers next-generation Windows Server 2008 Hyper-V virtualization technology from a managed hosting partner you can truly depend on. Visit www.maximumasp.com/max for a FREE 30 day trial. Hurry offer ends soon. Climb aboard the MaxV platform and take advantage of High Availability, Intelligent Monitoring, Recurrent Backups, and Scalability – with no hassle or hidden fees. As a managed hosting partner focused solely on Microsoft technologies since 2000, MaximumASP is uniquely qualified to provide the superior support that our business is built on. Unparalleled expertise with Microsoft technologies lead to working directly with Microsoft as first to offer IIS 7 and SQL 2008 betas in a hosted environment; partnering in the Go Live Program for Hyper-V; and product co-launches built on WS 2008 with Hyper-V technology.
    Finally – a virtual platform that delivers next-generation Windows Server 2008 Hyper-V virtualization technology from a managed hosting partner you can truly depend on. Visit www.maximumasp.com/max for a FREE 30 day trial. Hurry offer ends soon. Climb aboard the MaxV platform and take advantage of High Availability, Intelligent Monitoring, Recurrent Backups, and Scalability – with no hassle or hidden fees. As a managed hosting partner focused solely on Microsoft technologies since 2000, MaximumASP is uniquely qualified to provide the superior support that our business is built on. Unparalleled expertise with Microsoft technologies lead to working directly with Microsoft as first to offer IIS 7 and SQL 2008 betas in a hosted environment; partnering in the Go Live Program for Hyper-V; and product co-launches built on WS 2008 with Hyper-V technology.
6 Months Free & No Setup Fees ASP.NET Hosting!
Become a Sponsor