473,386 Members | 1,598 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

Simple Color Pallete control?

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
Oct 27 '06 #1
1 2947

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

Oct 30 '06 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: James Dean | last post by:
I want to put my own custom colors in the Pallete.....could someone tell me how to do this?. I tried the following: bitmap.Palette.Entries.SetValue(Color.White,0); This was supposed to set the...
2
by: Mc Spooney | last post by:
I have installed the open source C# IDE, Sharp Develop. Is there a component pallete to allow you to drag and drop controls, such as text boxes and labels etc onto a form ? If so how do you switch...
0
by: gt | last post by:
How can I check if an uploaded jpg uses a CMYK pallete? I'd like to test for this and either convert to a jpg that use RGB or prompt the user to do the conversion themselves. thanks
1
by: Onwuka Emeka | last post by:
is there a way to reduce or modify the color depth of a jpeg image, i currently need to programatically change the color depth of a jpeg image from 24bits to 8bits. any help would be appreciated
3
by: Vrijbuiter | last post by:
I want to detect a pixel color number when i move the mouse over de picturebox. I think the next line has the color but i don't now how i get it: System.Drawing.Point pt = new Point() ; pt.X...
1
by: =?Utf-8?B?bHM=?= | last post by:
my work recently purchased a Lenovo brand lap top for me The color on the computer is odd, not the same as other computers, desktop, programs, color pallete. red appears as orange, but prints red ?...
6
by: monikagovindaraj | last post by:
how to get the color pallete in single value from text box in php
1
by: monikagovindaraj | last post by:
hello sir, i want to create three columns on my table. the third column, i want to display each button has unique color. after am click that button it will be displayed the overall color...
5
by: randy.buchholz | last post by:
While more experienced users can pretty much tell a color from its hex, new users can't. Named colors do help with consistancy and new developers. Is it possible to create custom named color...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.