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 |