GUI
<Window x:Class="W005_Language.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:local="clr-namespace:W005_Language"
mc:Ignorable="d"
Title="MainWindow" Height="260" Width="300">
<StackPanel Margin="20">
<TextBlock HorizontalAlignment="Center"
Padding="0,5,0,5" Text="좋아하는 프로그래밍 언어를 선택하세요!"/>
<Separator Background="LightSteelBlue"/>
<CheckBox x:Name="cbC" Margin="30,5,0,0">C</CheckBox>
<CheckBox x:Name="cbPP" Margin="30,5,0,0">C++</CheckBox>
<CheckBox x:Name="cbCS" Margin="30,5,0,0">C#</CheckBox>
<CheckBox x:Name="cbPy" Margin="30,5,0,0">Python</CheckBox>
<CheckBox x:Name="cbJava" Margin="30,5,0,10">Java</CheckBox>
<Separator Background="LightBlue"/>
<StackPanel Margin="5,10" HorizontalAlignment="Center" Orientation="Horizontal">
<Button x:Name="btnSubmit" Width="80" Margin="0,0,20,0"
Click="btnSubmit_Click">투표하기</Button>
<Button x:Name="btnQuit" Width="80"
Click="btnQuit_Click" >끝내기</Button>
</StackPanel>
</StackPanel>
</Window>
코드작성
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
namespace W005_Language
{
/// <summary>
/// MainWindow.xaml에 대한 상호 작용 논리
/// </summary>
public partial class MainWindow : Window
{
CheckBox[] cbs;
public MainWindow()
{
InitializeComponent();
cbs = new CheckBox[]
{
cbC,cbPP,cbCS,cbPy,cbJava
};
}
//제출하기
private void btnSubmit_Click(object sender, RoutedEventArgs e)
{
string str = string.Empty;
foreach(var cb in cbs)
{
if (cb.IsChecked == true)
str += cb.Content + " , ";
}
MessageBox.Show(str + "Sekected!", "Language Prefered!");
}
//끝내기
private void btnQuit_Click(object sender, RoutedEventArgs e)
{
//this.Close();
Close();
}
}
}
'C# > Basics' 카테고리의 다른 글
W011. MulticColorButton (0) | 2021.04.25 |
---|---|
W010.UserControl (0) | 2021.04.25 |
W008.Login (0) | 2021.04.25 |
W007. ThreeButtons (0) | 2021.04.25 |
W006.HelloWorld (0) | 2021.04.25 |