728x90
반응형
728x170
▶ MainWindow.xaml
<Window x:Class="TestProject.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Width="800"
Height="600"
Title="ScrollBar 엘리먼트 : 색상 스크롤하기"
FontFamily="나눔고딕코딩"
FontSize="16">
<Grid>
<Grid Margin="10">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="200" />
<ColumnDefinition Width="Auto" />
<ColumnDefinition Width="*" />
</Grid.ColumnDefinitions>
<Grid Grid.Row="0" Grid.Column="0">
<Grid.RowDefinitions>
<RowDefinition Height="Auto" />
<RowDefinition Height="*" />
<RowDefinition Height="Auto" />
</Grid.RowDefinitions>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="*" />
<ColumnDefinition Width="*" />
<ColumnDefinition Width="*" />
</Grid.ColumnDefinitions>
<Label Grid.Row="0" Grid.Column="0"
HorizontalAlignment="Center"
Margin="10"
Content="적색" />
<ScrollBar Name="redScrollBar" Grid.Row="1" Grid.Column="0"
Margin="10"
Orientation="Vertical"
Focusable="True"
Minimum="0"
Maximum="255"
SmallChange="1"
LargeChange="16" />
<TextBlock Name="redTextBlock" Grid.Row="2" Grid.Column="0"
HorizontalAlignment="Center"
Margin="10"
TextAlignment="Center" />
<Label Grid.Row="0" Grid.Column="1"
HorizontalAlignment="Center"
Margin="10"
Content="녹색" />
<ScrollBar Name="greenScrollBar" Grid.Row="1" Grid.Column="1"
Margin="10"
Orientation="Vertical"
Focusable="True"
Minimum="0"
Maximum="255"
SmallChange="1"
LargeChange="16" />
<TextBlock Name="greenTextBlock" Grid.Row="2" Grid.Column="1"
HorizontalAlignment="Center"
Margin="10"
TextAlignment="Center" />
<Label Grid.Row="0" Grid.Column="2"
HorizontalAlignment="Center"
Margin="10"
Content="청색" />
<ScrollBar Name="blueScrollBar" Grid.Row="1" Grid.Column="2"
Margin="10"
Orientation="Vertical"
Focusable="True"
Minimum="0"
Maximum="255"
SmallChange="1"
LargeChange="16" />
<TextBlock Name="blueTextBlock" Grid.Row="2" Grid.Column="3"
HorizontalAlignment="Center"
Margin="10"
TextAlignment="Center" />
</Grid>
<GridSplitter Grid.Row="0" Grid.Column="1"
HorizontalAlignment="Center"
VerticalAlignment="Stretch"
Width="10" />
<StackPanel Name="stackPanel" Grid.Row="0" Grid.Column="2"
Background="{StaticResource {x:Static SystemColors.WindowBrushKey}}" />
</Grid>
</Grid>
</Window>
728x90
▶ MainWindow.xaml.cs
using System.Windows;
using System.Windows.Controls;
using System.Windows.Controls.Primitives;
using System.Windows.Media;
namespace TestProject
{
/// <summary>
/// 메인 윈도우
/// </summary>
public partial class MainWindow : Window
{
//////////////////////////////////////////////////////////////////////////////////////////////////// Constructor
////////////////////////////////////////////////////////////////////////////////////////// Public
#region 생성자 - MainWindow()
/// <summary>
/// 생성자
/// </summary>
public MainWindow()
{
InitializeComponent();
Loaded += Window_Loaded;
this.redScrollBar.ValueChanged += colorScrollBar_ValueChanged;
this.greenScrollBar.ValueChanged += colorScrollBar_ValueChanged;
this.blueScrollBar.ValueChanged += colorScrollBar_ValueChanged;
}
#endregion
//////////////////////////////////////////////////////////////////////////////////////////////////// Method
////////////////////////////////////////////////////////////////////////////////////////// Private
#region 윈도우 로드시 처리하기 - Window_Loaded(sender, e)
/// <summary>
/// 윈도우 로드시 처리하기
/// </summary>
/// <param name="sender">이벤트 발생자</param>
/// <param name="e">이벤트 인자</param>
private void Window_Loaded(object sender, RoutedEventArgs e)
{
Color color = (this.stackPanel.Background as SolidColorBrush).Color;
this.redScrollBar.Value = color.R;
this.greenScrollBar.Value = color.G;
this.blueScrollBar.Value = color.B;
this.redScrollBar.Focus();
}
#endregion
#region 색상 스크롤바 값 변경시 처리하기 - colorScrollBar_ValueChanged(sender, e)
/// <summary>
/// 색상 스크롤바 값 변경시 처리하기
/// </summary>
/// <param name="sender">이벤트 발생자</param>
/// <param name="e">이벤트 인자</param>
private void colorScrollBar_ValueChanged(object sender, RoutedPropertyChangedEventArgs<double> e)
{
ScrollBar scrollBar = sender as ScrollBar;
Panel panel = scrollBar.Parent as Panel;
TextBlock textBlock;
if(scrollBar == this.redScrollBar)
{
textBlock = this.redTextBlock;
}
else if(scrollBar == this.greenScrollBar)
{
textBlock = this.greenTextBlock;
}
else
{
textBlock = this.blueTextBlock;
}
textBlock.Text = string.Format("{0}\n0x{0:X2}", (int)scrollBar.Value);
this.stackPanel.Background = new SolidColorBrush
(
Color.FromRgb
(
(byte)redScrollBar.Value,
(byte)greenScrollBar.Value,
(byte)blueScrollBar.Value
)
);
}
#endregion
}
}
728x90
반응형
그리드형(광고전용)
'C# > WPF' 카테고리의 다른 글
[C#/WPF] CachedBitmap 클래스 사용하기 (0) | 2020.08.05 |
---|---|
[C#/WPF] TransformedBitmap 클래스 사용하기 (0) | 2020.08.05 |
[C#/WPF] BmpBitmapDecoder 클래스 : BMP 이미지 파일 로드하기 (Uri 사용) (0) | 2020.08.05 |
[C#/WPF] BmpBitmapDecoder 클래스 : BMP 이미지 파일 로드하기 (FileStrem 사용) (0) | 2020.08.05 |
[C#/WPF] DoubleAnimation 엘리먼트 : EasingFunction 속성에서 BackEase 객체 사용하기 (0) | 2020.08.05 |
[C#/WPF] o:Freeze 속성 : Freezable 엘리먼트의 IsFrozen 속성 상태를 true로 설정하기 (0) | 2020.08.04 |
[C#/WPF] GridSplitter 엘리먼트 사용하기 (0) | 2020.08.04 |
[C#/WPF] Grid 엘리먼트 : ShowGridLines 속성 사용하기 (0) | 2020.08.04 |
[C#/WPF] 도형 위치/크기 변경하기 (0) | 2020.08.04 |
[C#/WPF] 도형 위치/크기 변경하기 (Polygon 제외) (0) | 2020.08.04 |
댓글을 달아 주세요