GUI
<Window x:Class="W012_UniformGrid.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:W012_UniformGrid"
mc:Ignorable="d"
Title="MainWindow" Height="500" Width="500">
<UniformGrid x:Name="chaessBoard">
</UniformGrid>
</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 W012_UniformGrid
{
/// <summary>
/// MainWindow.xaml에 대한 상호 작용 논리
/// </summary>
public partial class MainWindow : Window
{
public MainWindow()
{
InitializeComponent();
chaessBoard.Rows = 8;
chaessBoard.Columns = 8;
for(int i = 0; i < 64 / 2; i++)
{
//짝수줄은 검은색, 빨간색
//홀수줄은 빨간색, 검은색
if ((i / 4) % 2 == 0) // 짝수줄 0,2,4...
{
Rectangle r1 = new Rectangle();
r1.Fill = Brushes.Black;
chaessBoard.Children.Add(r1);
Rectangle r2 = new Rectangle();
r2.Fill = Brushes.Red;
chaessBoard.Children.Add(r2);
}
else
{
Rectangle r2 = new Rectangle();
r2.Fill = Brushes.Red;
chaessBoard.Children.Add(r2);
Rectangle r1 = new Rectangle();
r1.Fill = Brushes.Black;
chaessBoard.Children.Add(r1);
}
}
}
}
}
'C# > Basics' 카테고리의 다른 글
W014. WindowsCalc (0) | 2021.04.25 |
---|---|
W013. Event (0) | 2021.04.25 |
W011. MulticColorButton (0) | 2021.04.25 |
W010.UserControl (0) | 2021.04.25 |
W009. Language (0) | 2021.04.25 |