调色板程序

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

namespace  testgrid
{
    
public partial class ColorScroll : Form
    
{
        Panel panel;
        Label[] alabelName 
= new Label[3];
        Label[] alabelValue 
= new Label[3];
        VScrollBar[] avscroll 
= new VScrollBar[3];
        
public ColorScroll()
        
{
            Color[] acolor 
={ Color.Red, Color.Green, Color.Blue };
            panel 
= new Panel();
            panel.Parent 
= this;
            panel.Location 
= new Point(00);
            panel.BackColor 
= Color.White;
            
for (int i = 0; i < 3; i++)
            
{
                alabelName[i] 
= new Label();
                alabelName[i].Parent 
= panel;
                alabelName[i].ForeColor 
= acolor[i];
                alabelName[i].Text 
= "&" + acolor[i].ToKnownColor();
                alabelName[i].TextAlign 
= ContentAlignment.MiddleCenter;

                avscroll[i] 
= new VScrollBar();
                avscroll[i].Parent 
= panel;
                avscroll[i].SmallChange 
= 1;
                avscroll[i].LargeChange 
= 16;
                avscroll[i].Minimum 
= 0;
                avscroll[i].Maximum 
= 255 + avscroll[i].LargeChange - 1;
                avscroll[i].ValueChanged 
+= new EventHandler(ColorScroll_ValueChanged);
                avscroll[i].TabStop 
= true;

                alabelValue[i] 
= new Label();
                alabelValue[i].Parent 
= panel;
                alabelValue[i].TextAlign 
= ContentAlignment.MiddleCenter;
            }

            Color color 
= BackColor;
            avscroll[
0].Value = color.R;
            avscroll[
1].Value = color.G;
            avscroll[
2].Value = color.B;
            OnResize(EventArgs.Empty);
            InitializeComponent();
        }

        
protected override void OnResize(EventArgs e)
        
{
            
base.OnResize(e);
            
int cx = ClientSize.Width;
            
int cy = ClientSize.Height;
            
int cyFont = Font.Height;
            panel.Size 
= new Size(cx / 2, cy);
            
for (int i = 0; i < 3; i++)
            
{
                alabelName[i].Location 
= new Point(i * cx / 6, cyFont / 2);
                alabelName[i].Size 
= new Size(cx / 6, cyFont);
                avscroll[i].Location 
= new Point((4 * i + 1* cx / 242 * cyFont);
                avscroll[i].Size 
= new Size(cx / 12, cy - 4 * cyFont);
                alabelValue[i].Location 
= new Point(i * cx / 6, cy - 3 * cyFont / 2);
                alabelValue[i].Size 
= new Size(cx / 6, cyFont);
            }

        }

        
void ColorScroll_ValueChanged(object sender, EventArgs e)
        
{
            
//throw new Exception("The method or operation is not implemented.");
            for (int i = 0; i < 3; i++)
            
{
                
if ((VScrollBar)sender == avscroll[i])
                
{
                    alabelValue[i].Text 
= avscroll[i].Value.ToString();
                }

                
            }

            BackColor 
= Color.FromArgb(avscroll[0].Value, avscroll[1].Value, avscroll[2].Value);
        }

    }

}
 
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值