日期:2014-05-18  浏览次数:21261 次

C#调色板如何显示颜色
用C#的什么控件能够显示颜色?我在做一个调色板程序,但是只能改变字体颜色,却无法改变某一控件的颜色或者在某一区域显示调出的颜色。
以下是代码,请指教


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

namespace _1113640111秦超
{
  public partial class Form1 : Form
  {
  int r, g, b;
  public Form1()
  {
  InitializeComponent();
  }

  private void hScrollBar1_Scroll(object sender, ScrollEventArgs e)
  {
  textBox1.Text = (hScrollBar1.Value).ToString();
  listBox1 .BackColor = System.Drawing.Color.FromArgb(r = hScrollBar1.Value);
  }

  private void hScrollBar2_Scroll(object sender, ScrollEventArgs e)
  {
  textBox2.Text = (hScrollBar2.Value).ToString();
  listBox1.BackColor = System.Drawing.Color.FromArgb(g = hScrollBar2.Value);
  }

  private void hScrollBar3_Scroll(object sender, ScrollEventArgs e)
  {
  textBox3.Text = (hScrollBar3.Value).ToString();
  listBox1.BackColor = System.Drawing.Color.FromArgb(b = hScrollBar3.Value);
  }
  }
}


------解决方案--------------------
C#调用调色板
C# code

            ColorDialog colorDialog1 = new ColorDialog();
            colorDialog1.FullOpen = true; //是否显示ColorDialog有半部分
            //colorDialog1.CustomColors = colorDialog1.Color;//设置自定义颜色
            DialogResult result = colorDialog1.ShowDialog();
            if (result == DialogResult.OK)//确定事件响应
            {
                Color color_from = colorDialog1.Color;
                int a = color_from.R;
                int b = color_from.G;
                int c = color_from.B;
                string str;
                str=a.ToString()+"  "+b.ToString()+"  "+c.ToString()+"  ";
                MessageBox.Show(str);
            }

------解决方案--------------------
如果我想把颜色值转成Int类型的应该怎么办呢。
------解决方案--------------------
探讨

如果我想把颜色值转成Int类型的应该怎么办呢。