WPF Web Based

WPF Examples

WPF

WPF Projects

WPF Project

adplus-dvertising
RadioButton Control in WPF WEB BASED
Previous Home Next

RadioButton controls are usually grouped together to offer user a single choice among Diffrent options (only one button at a time can be selected).

<RadioButton> </Radiobutton>

Tag is used to create the radio button in XAML File.

Syntax of RadioButton:

<RadioButton Height="18" Margin="92,58,0,0" Name="radioButton1"
        VerticalAlignment="Top" HorizontalAlignment="Left"
        Width="82">RadioButton
</RadioButton>

In the following tag I create the RadioButton in which Height is height of the RadioButton, Name is the nameof the RadioButton, text in the between the RadioButton tag is the centent visibile to user.

The Background and Foreground properties represent the background and foreground colors of a RadioButton.

The following code sets the name, height, and width of a RadioButton control. The code also sets horizontal alignment to left and vertical alignment to top.

Example:

.XAML Code:

<Page x:Class="WpfBrowserApplication5.Page5"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Title="Page5" Background="LightGoldenrodYellow" 
Height="182" Width="275" Loaded="Page_Loaded">
<Grid>
<RadioButton Height="18" Margin="92,58,0,0" Name="radioButton1" 
      VerticalAlignment="Top" HorizontalAlignment="Left" Width="82" 
	  Background="Crimson" Foreground="DarkBlue">M.Tech</RadioButton>
<RadioButton Height="17" Margin="92,85,126,0" Name="radioButton2" 
VerticalAlignment="Top" Checked="radioButton2_Checked" 
Background="Crimson" Foreground="DarkBlue">B.Tech</RadioButton>
<RadioButton Height="17" Margin="92,115,126,0" Name="radioButton3"
VerticalAlignment="Top" Checked="radioButton3_Checked" Background="Crimson"
Foreground="DarkBlue">MCA</RadioButton>
<RadioButton Height="20" Margin="92,141,126,0" Name="radioButton4"
     VerticalAlignment="Top" Background="Crimson" 
     Foreground="DarkBlue">BCA</RadioButton>
<Label Height="32" Margin="20,15,0,0" Name="label1"
VerticalAlignment="Top" HorizontalAlignment="Left"
Width="171" FontSize="18" Foreground="DarkGreen">Plese Select Course
</Label>
<Button Height="22.861" HorizontalAlignment="Right" Margin="0,53.139,18,0"
        Name="button1" VerticalAlignment="Top" Width="102" Click="button1_Click">
		Find Selected Item</Button>
</Grid>
</Page>

.XAML.CS Code:

private void button1_Click(object sender, RoutedEventArgs e)
{
if (radioButton1.IsChecked == true)
{
MessageBox.Show("Your Selected Course is " + radioButton1.Content);
}
else if (radioButton2.IsChecked == true)
{
MessageBox.Show("Your Selected Course is " + radioButton2.Content);
}
else if (radioButton3.IsChecked == true)
{
MessageBox.Show("Your Selected Course is " + radioButton3.Content);
}
else if (radioButton4.IsChecked == true)
{
MessageBox.Show("Your Selected Course is " + radioButton4.Content);
}
}		
Previous Home Next
WPF Examples

WPF

WPF

WPF

WPF

WPF

WPF

WPF

WPF