RadioButton Control Using WPF Window Based
RadioButton controls are usually grouped together to offer user a single choice among Different 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 controls are usually grouped together to offer user a single choice among Different 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
name of the RadioButton, text in the between the RadioButton tag is the
content visible 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
XAML Code
<Window x:Class="WpfApplication7.Window1"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Title="Window1" Height="370" Width="417"><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>
<UniformGrid Margin="110,123,84,109" Name="uniformGrid1" />
</Grid>
</Window>
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);
}
}
private void radioButton3_Checked(object sender, RoutedEventArgs e){}
private void radioButton2_Checked(object sender, RoutedEventArgs e) {}
No comments:
Post a Comment