Загрузка данных
<Window x:Class="RadioButtonLab.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Title="Практическая работа RadioButton"
Height="800"
Width="700">
<ScrollViewer>
<StackPanel Margin="20">
<!-- Задание 1 -->
<TextBlock Text="Задание 1. Выбор языка"
FontSize="18"
FontWeight="Bold"/>
<WrapPanel Margin="0,10">
<RadioButton Content="Русский" Checked="Language_Checked"/>
<RadioButton Content="English" Margin="10,0" Checked="Language_Checked"/>
<RadioButton Content="Deutsch" Margin="10,0" Checked="Language_Checked"/>
<RadioButton Content="Français" Margin="10,0" Checked="Language_Checked"/>
<RadioButton Content="Español" Margin="10,0" Checked="Language_Checked"/>
<RadioButton Content="Italiano" Margin="10,0" Checked="Language_Checked"/>
<RadioButton Content="Português" Margin="10,0" Checked="Language_Checked"/>
<RadioButton Content="Polski" Margin="10,0" Checked="Language_Checked"/>
<RadioButton Content="中文" Margin="10,0" Checked="Language_Checked"/>
<RadioButton Content="日本語" Margin="10,0" Checked="Language_Checked"/>
</WrapPanel>
<Separator Margin="0,15"/>
<!-- Задание 2 -->
<TextBlock Text="Задание 2. Армия"
FontSize="18"
FontWeight="Bold"/>
<TextBlock Text="Хотите служить в армии?"
Margin="0,10"/>
<RadioButton x:Name="rbYes"
Content="Да"
IsChecked="True"/>
<RadioButton x:Name="rbNo"
Content="Нет"
Checked="rbNo_Checked"/>
<Separator Margin="0,15"/>
<!-- Задание 3 -->
<TextBlock Text="Задание 3. Угадай число"
FontSize="18"
FontWeight="Bold"/>
<WrapPanel Margin="0,10">
<RadioButton Content="1" Checked="Number_Checked"/>
<RadioButton Content="2" Checked="Number_Checked"/>
<RadioButton Content="3" Checked="Number_Checked"/>
<RadioButton Content="4" Checked="Number_Checked"/>
<RadioButton Content="5" Checked="Number_Checked"/>
<RadioButton Content="6" Checked="Number_Checked"/>
<RadioButton Content="7" Checked="Number_Checked"/>
<RadioButton Content="8" Checked="Number_Checked"/>
<RadioButton Content="9" Checked="Number_Checked"/>
<RadioButton Content="10" Checked="Number_Checked"/>
</WrapPanel>
<Separator Margin="0,15"/>
<!-- Задание 4 -->
<TextBlock Text="Задание 4. Цвета"
FontSize="18"
FontWeight="Bold"/>
<TextBlock x:Name="txtColor"
Text="Текст меняет цвет"
FontSize="24"
Margin="0,10"/>
<WrapPanel>
<RadioButton Content="Red" Checked="Color_Checked"/>
<RadioButton Content="Blue" Margin="10,0" Checked="Color_Checked"/>
<RadioButton Content="Green" Margin="10,0" Checked="Color_Checked"/>
<RadioButton Content="Yellow" Margin="10,0" Checked="Color_Checked"/>
<RadioButton Content="Orange" Margin="10,0" Checked="Color_Checked"/>
<RadioButton Content="Purple" Margin="10,0" Checked="Color_Checked"/>
<RadioButton Content="Black" Margin="10,0" Checked="Color_Checked"/>
</WrapPanel>
<Separator Margin="0,15"/>
<!-- Задание 5 -->
<TextBlock Text="Задание 5. Часовые пояса"
FontSize="18"
FontWeight="Bold"/>
<StackPanel Margin="0,10">
<RadioButton Content="Москва" Checked="City_Checked"/>
<RadioButton Content="Лондон" Checked="City_Checked"/>
<RadioButton Content="Париж" Checked="City_Checked"/>
<RadioButton Content="Токио" Checked="City_Checked"/>
<RadioButton Content="Пекин" Checked="City_Checked"/>
<RadioButton Content="Нью-Йорк" Checked="City_Checked"/>
<RadioButton Content="Сидней" Checked="City_Checked"/>
</StackPanel>
</StackPanel>
</ScrollViewer>
</Window>
using System;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Media;
namespace RadioButtonLab
{
public partial class MainWindow : Window
{
Random rnd = new Random();
int secret;
public MainWindow()
{
InitializeComponent();
secret = rnd.Next(1, 11);
}
// Задание 1
private void Language_Checked(object sender, RoutedEventArgs e)
{
RadioButton rb = sender as RadioButton;
MessageBox.Show(
"Вы выбрали язык: " + rb.Content);
}
// Задание 2
private void rbNo_Checked(object sender, RoutedEventArgs e)
{
MessageBox.Show(
"Спасибо за положительный ответ!");
rbYes.IsChecked = true;
}
// Задание 3
private void Number_Checked(object sender, RoutedEventArgs e)
{
RadioButton rb = sender as RadioButton;
int number = Convert.ToInt32(rb.Content);
string[] roman =
{
"",
"I","II","III","IV","V",
"VI","VII","VIII","IX","X"
};
rb.ToolTip = roman[number];
if (number == secret)
{
MessageBox.Show("Вы угадали!");
secret = rnd.Next(1, 11);
}
}
// Задание 4
private void Color_Checked(object sender, RoutedEventArgs e)
{
RadioButton rb = sender as RadioButton;
txtColor.Foreground =
(Brush)new BrushConverter()
.ConvertFromString(rb.Content.ToString());
}
// Задание 5
private void City_Checked(object sender, RoutedEventArgs e)
{
RadioButton rb = sender as RadioButton;
string city = rb.Content.ToString();
string zone = "";
switch (city)
{
case "Москва":
zone = "GMT+3";
break;
case "Лондон":
zone = "GMT+0";
break;
case "Париж":
zone = "GMT+1";
break;
case "Токио":
zone = "GMT+9";
break;
case "Пекин":
zone = "GMT+8";
break;
case "Нью-Йорк":
zone = "GMT-5";
break;
case "Сидней":
zone = "GMT+10";
break;
}
MessageBox.Show($"{city} — {zone}");
}
}
}