결과

 

디자인
스크롤바 최값대 255 값 설정.

 

  <Grid>
      <Grid.ColumnDefinitions>
        <ColumnDefinition Width="100"/>
        <ColumnDefinition Width="250"/>
        <ColumnDefinition Width="150"/>
      </Grid.ColumnDefinitions>
      <Grid.RowDefinitions>
        <RowDefinition/>
        <RowDefinition/>
        <RowDefinition/>
      </Grid.RowDefinitions>

그리드 행렬 (3x3) .  그리드 속성 definition - Width설정

 

 

cs 코드

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 WpfApplication13
{
    /// <summary>
    /// MainWindow.xaml에 대한 상호 작용 논리
    /// </summary>
    public partial class MainWindow : Window
    {
        public MainWindow()
        {
            InitializeComponent();

            txtR.Text = "0";
            txtG.Text = "0";
            txtB.Text = "0";

            scrR.Value = 0;
            scrG.Value = 0;
            scrB.Value = 0;
        }

        private void scr_ValueChanged(object sender, RoutedPropertyChangedEventArgs<double> e)
        {
            byte valueR = (byte)scrR.Value;
            byte valueG = (byte)scrG.Value;
            byte valueB = (byte)scrB.Value;

            txtR.Text = valueR.ToString();
            txtG.Text = valueG.ToString();
            txtB.Text = valueB.ToString();

            canvas_bg.Background = new SolidColorBrush(Color.FromArgb(255, valueR, valueG, valueB));
        }

        private void txtR_Changed(object sender, TextChangedEventArgs e)
        {
            if (txtR.Text == "")
                return;

            scrR.Value = int.Parse(txtR.Text);
            canvas_bg.Background = new SolidColorBrush(Color.FromArgb(255, (byte)scrR.Value, (byte)scrG.Value, (byte)scrB.Value));

        }

        private void txtG_Changed(object sender, TextChangedEventArgs e)
        {
            if (txtG.Text == "")
                return;

            scrG.Value = int.Parse(txtG.Text);
            canvas_bg.Background = new SolidColorBrush(Color.FromArgb(255, (byte)scrR.Value, (byte)scrG.Value, (byte)scrB.Value));
        }

        private void txtB_Changed(object sender, TextChangedEventArgs e)
        {
            if (txtB.Text == "")
                return;

            scrB.Value = int.Parse(txtB.Text);
            canvas_bg.Background = new SolidColorBrush(Color.FromArgb(255, (byte)scrR.Value, (byte)scrG.Value, (byte)scrB.Value));
        }
    }
}

 

 

xaml 소스

<Window x:Class="WpfApplication13.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:WpfApplication13"
        mc:Ignorable="d"
        Title="MainWindow" Height="420" Width="559.408">
    <Grid>
        <Canvas x:Name="canvas_bg" HorizontalAlignment="Left" Height="134" VerticalAlignment="Top" Width="459" Margin="35,0,0,0">
            <Grid Height="194" Width="495" Canvas.Left="-18" Canvas.Top="155">
                <Grid.RowDefinitions>
                    <RowDefinition/>
                    <RowDefinition/>
                    <RowDefinition/>
                </Grid.RowDefinitions>
                <Grid.ColumnDefinitions>
                    <ColumnDefinition Width="0.2*"/>
                    <ColumnDefinition Width="0.8*"/>
                    <ColumnDefinition Width="0.3*"/>
                </Grid.ColumnDefinitions>
                <Label x:Name="label" Content="Red" HorizontalAlignment="Left" VerticalAlignment="Top" Margin="10,10,0,0" Height="45" FontSize="20" Width="56"/>
                <Label x:Name="label_Copy" Content="Green" HorizontalAlignment="Left" VerticalAlignment="Top" Margin="10,9,0,0" Height="45" FontSize="18" Width="66" Grid.Row="1"/>
                <Label x:Name="label_Copy1" Content="Blue" HorizontalAlignment="Left" VerticalAlignment="Top" Margin="10,10,0,0" Height="45" FontSize="20" Width="56" Grid.Row="2"/>
                <ScrollBar x:Name="scrR" HorizontalAlignment="Left" VerticalAlignment="Top" Grid.Column="1" Margin="10,12,0,0" Orientation="Horizontal" Height="42" Width="295" ValueChanged="scr_ValueChanged" Maximum="255"/>
                <ScrollBar x:Name="scrG" HorizontalAlignment="Left" Grid.Column="1" Margin="10,12,0,11" Orientation="Horizontal" Height="Auto" Width="295" Grid.Row="1" ValueChanged="scr_ValueChanged" Maximum="255"/>
                <ScrollBar x:Name="scrB" HorizontalAlignment="Left" VerticalAlignment="Top" Grid.Column="1" Margin="10,12,0,0" Orientation="Horizontal" Height="41" Width="295" Grid.Row="2" ValueChanged="scr_ValueChanged" Maximum="255"/>
            </Grid>
        </Canvas>
        <ScrollBar x:Name="scrollBar1" HorizontalAlignment="Left" Margin="766,274,-270,0" VerticalAlignment="Top"/>
        <TextBox x:Name="txtR" HorizontalAlignment="Left" Height="43" TextWrapping="Wrap" VerticalAlignment="Top" Width="86" Margin="417,167,0,0" FontSize="18" TextChanged="txtR_Changed"/>
        <TextBox x:Name="txtG" HorizontalAlignment="Left" Height="43" TextWrapping="Wrap" VerticalAlignment="Top" Width="86" Margin="417,232,0,0" RenderTransformOrigin="0.54,2.331" FontSize="18" TextChanged="txtG_Changed"/>
        <TextBox x:Name="txtB" HorizontalAlignment="Left" Height="43" TextWrapping="Wrap" VerticalAlignment="Top" Width="86" Margin="417,295,0,0" FontSize="18" TextChanged="txtB_Changed"/>

    </Grid>
</Window>

 

참조.

C# .NET 39 스크롤바와 슬라이더로 RGB 컬러 조정(WPF) : 네이버 포스트 (naver.com) 

 

+ Recent posts