C#/C#200제

[C#] 19일차 - 139. 스크롤바로 RGB 컬러 조정

반나무 2021. 2. 19. 20:09

 

이벤트 설정

 

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace A139_RgbScrollBar
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
			
            // 초기화
            this.BackColor = Color.LightSteelBlue;
            panel1.BackColor = Color.FromArgb(0, 0, 0);
            txtR.Text = 0.ToString();
            txtG.Text = 0.ToString();
            txtB.Text = 0.ToString();
            scrR.Maximum = 255 + 9;
            scrG.Maximum = 255 + 9;
            scrB.Maximum = 255 + 9;

        }
		// 스크롤을 변경했을 때
        private void src_Scroll(object sender, ScrollEventArgs e)
        {
            txtR.Text = scrR.Value.ToString();
            txtG.Text = scrG.Value.ToString();
            txtB.Text = scrB.Value.ToString();
            panel1.BackColor = Color.FromArgb(scrR.Value, scrG.Value, scrB.Value);
        }

		// txt를 변경했을 때
        private void txt_TextChanged(object sender, EventArgs e)
        {
            if(txtR.Text != "" && txtG.Text != "" && txtB.Text != "")
            {
                scrR.Value = int.Parse(txtR.Text);
                scrG.Value = int.Parse(txtG.Text);
                scrB.Value = int.Parse(txtB.Text);
                panel1.BackColor = Color.FromArgb(scrR.Value, scrG.Value, scrB.Value);

            }
        }
    }
}

반응형