W010.UserControl

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

GUI

<Window x:Class="W006_UserControl.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:W006_UserControl"
        mc:Ignorable="d"
        Title="MainWindow" Height="450" Width="500">
    <DockPanel>
        <TextBlock DockPanel.Dock="Top" HorizontalAlignment="Center" FontSize="20"
                   FontWeight="Bold" Margin="20,20,20,10" Text="Color Test"/>
        <StackPanel DockPanel.Dock="Top" Orientation="Horizontal" HorizontalAlignment="Center">
            <Button x:Name="btnRed" Margin="20" Width="50" Height="50"
                    Click="btnRed_Click">
                <StackPanel>
                    <Rectangle Fill="Red" Width="25" Height="25"/>
                    <TextBlock HorizontalAlignment="Center" Text="Red"/>
                </StackPanel>
            </Button>
            <Button x:Name="btnGreen" Margin="20" Width="50" Height="50"
                    Click="btnGreen_Click">
                <StackPanel>
                    <Rectangle Fill="Green" Width="25" Height="25"/>
                    <TextBlock HorizontalAlignment="Center" Text="Green"/>
                </StackPanel>
            </Button>
            <Button x:Name="btnBlue" Margin="20" Width="50" Height="50"
                    Click="btnBlue_Click">
                <StackPanel>
                    <Rectangle Fill="Blue" Width="25" Height="25"/>
                    <TextBlock HorizontalAlignment="Center" Text="Blue"/>
                </StackPanel>
            </Button>
        </StackPanel>
        <Button DockPanel.Dock="Bottom" x:Name="btnColor" Margin="30,10,30,30" MinWidth="400" MinHeight="220"/>
    </DockPanel>
</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 W006_UserControl
{
    /// <summary>
    /// MainWindow.xaml에 대한 상호 작용 논리
    /// </summary>
    public partial class MainWindow : Window
    {
        public MainWindow()
        {
            InitializeComponent();
        }

        private void btnRed_Click(object sender, RoutedEventArgs e)
        {
            btnColor.Background = Brushes.Red;
        }

        private void btnGreen_Click(object sender, RoutedEventArgs e)
        {
            btnColor.Background = Brushes.Green;
        }

        private void btnBlue_Click(object sender, RoutedEventArgs e)
        {
            btnColor.Background = Brushes.Blue;
        }
    }
}
저작자표시 비영리 동일조건 (새창열림)

'C# > Basics' 카테고리의 다른 글

W012. UniformGrid  (0) 2021.04.25
W011. MulticColorButton  (0) 2021.04.25
W009. Language  (0) 2021.04.25
W008.Login  (0) 2021.04.25
W007. ThreeButtons  (0) 2021.04.25
'C#/Basics' 카테고리의 다른 글
  • W012. UniformGrid
  • W011. MulticColorButton
  • W009. Language
  • W008.Login
페프
페프
페프
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
페프
W010.UserControl
상단으로

티스토리툴바

개인정보

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

단축키

내 블로그

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

블로그 게시글

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

모든 영역

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

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