W012. UniformGrid

2021. 4. 25. 21:46· C#/Basics

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
'C#/Basics' 카테고리의 다른 글
  • W014. WindowsCalc
  • W013. Event
  • W011. MulticColorButton
  • W010.UserControl
페프
페프
페프
FFeFF SPACE
페프
전체
오늘
어제
  • 분류 전체보기
    • C++
      • Foundation
      • Programmers
    • C#
      • Foundation
      • Basics
    • Algorithms
    • SQLD
    • Web
      • JavaScript
    • AI-900
    • ETC

블로그 메뉴

  • About
  • 📗 Github
  • Programming_II
hELLO · Designed By 정상우.v4.2.2
페프
W012. UniformGrid
상단으로

티스토리툴바

개인정보

  • 티스토리 홈
  • 포럼
  • 로그인

단축키

내 블로그

내 블로그 - 관리자 홈 전환
Q
Q
새 글 쓰기
W
W

블로그 게시글

글 수정 (권한 있는 경우)
E
E
댓글 영역으로 이동
C
C

모든 영역

이 페이지의 URL 복사
S
S
맨 위로 이동
T
T
티스토리 홈 이동
H
H
단축키 안내
Shift + /
⇧ + /

* 단축키는 한글/영문 대소문자로 이용 가능하며, 티스토리 기본 도메인에서만 동작합니다.