Not sure if this is what you're after, but I threw this together this
morning. You'll need to add code to cleanup the picture boxes it creates,
but it might form the basis of a control of your own. See if it helps...
Create a new (blank) form and stuff this code in it. You should get a 7
column by 9 row of colours that the user can click on to pick a colour.
Steve
private void Form1_Load(object sender, EventArgs e)
{
BuildPictureList();
}
private void BuildPictureList()
{
System.Windows.Forms.PictureBox[] colourArray = new PictureBox[63];
Color[,] colourSelection = {
{ RGB(128, 5, 5), RGB(128, 80, 0),
RGB(10, 128, 10), RGB(10, 100, 100),
RGB(0, 0, 112), RGB(128, 0, 128),
RGB(0, 0, 0) },
{ RGB(192, 0, 0), RGB(192, 192, 50),
RGB(0, 192, 0),RGB(64, 192, 192),
RGB(0, 0, 202), RGB(192, 64, 192),
RGB(64, 64, 64) },
{ RGB(255, 0, 0), RGB(255, 255, 0),
RGB(0, 255, 0), RGB(0, 255, 255),
RGB(0, 0, 255), RGB(255, 0, 255),
RGB(96, 96, 96) },
{ RGB(255, 64, 64), RGB(255, 255, 64),
RGB(72, 255, 72), RGB(64, 255, 255),
RGB(72, 72, 255), RGB(255, 64, 255),
RGB(128, 128, 128) },
{ RGB(255, 128, 128), RGB(255, 255, 192),
RGB(138, 255, 138), RGB(192, 255, 255),
RGB(128, 128, 255), RGB(255, 128, 255),
RGB(176, 176, 176) },
{ RGB(255, 160, 160), RGB(255, 160, 50),
RGB(180, 255, 180), RGB(225, 252, 252),
RGB(180, 180, 255), RGB(221, 156, 179),
RGB(210, 210, 210) },
{ RGB(255, 35, 170), RGB(255, 128, 0),
RGB(220, 245, 220), RGB(160, 224, 224),
RGB(192, 192, 255), RGB(160, 98, 122),
RGB(255, 255, 255) },
{ RGB(226, 25, 136), RGB(222, 105, 0),
RGB(208, 195, 10), RGB(0, 160, 240),
RGB(140, 70, 255), RGB(128, 32, 96),
RGB(172, 135, 80) },
{ RGB(182, 32, 96), RGB(142, 94, 66),
RGB(160, 150, 0), RGB(0, 128, 192),
RGB(106, 53, 206), RGB(96, 0, 128),
RGB(235, 222, 160) }
};
for (int rows = 0; rows < 9; rows++)
for (int cols = 0; cols < 7; cols++)
{
int colourBox = (rows * 7) + cols;
colourArray[colourBox] = new PictureBox();
colourArray[colourBox].Size = new Size(20, 20);
colourArray[colourBox].Location = new Point(10 + (cols * 20), 10 +
(rows * 20));
colourArray[colourBox].Visible = true;
colourArray[colourBox].BorderStyle = BorderStyle.Fixed3D;
colourArray[colourBox].Name = String.Format("colorBox{0}",
colourBox);
colourArray[colourBox].BackColor = colourSelection[rows, cols];
colourArray[colourBox].Click += new
System.EventHandler(colorBox_Click);
this.Controls.Add(colourArray[colourBox]);
}
}
private Color RGB(int red, int green, int blue)
{
string htmlColor = String.Format("#{0:x2}{1:x2}{2:x2}", red, green, blue);
return ColorTranslator.FromHtml(htmlColor);
}
private void colorBox_Click(object sender, EventArgs e)
{
PictureBox picClicked = (PictureBox)sender;
MessageBox.Show(String.Format("You clicked on {0}", picClicked.Name));
}
"James Kenneth" <jk******@gmail.comwrote in message
news:10******************************@40tude.net.. .
>I need a simple color pallete control, similar to one that exists in
appearance section in dialog properties. Here is a screenshot:
http://tinyurl.com/y6m78k
I tried using ColorDialog but there doesn't seem to be a way to have only
a
couple of colors displayed. Is there a way to customize ColorDialog so
that
it only displayes several colors I chose? If not I would appreaciate if
somebody could give me a few pointers on how to create such a control
myself. Thanks in advance.
James