i want to loop through each avaiable color in Color struct.
Is that possible?

Recommended Answers

Depends on what you want Serkan.
This http://www.daniweb.com/code/snippet1022.html loops through what is called the KnowColors.
All the colors would need 256*256*256 iterations I guess.

Jump to Post

You also could create a file and read it in.
One of the lines would be the values of this:

Color c = Color.CornflowerBlue;
            int Alpha = c.A;
            int Red = c.R;
            int Green = c.G;
            int Blue = c.B;
Jump to Post

All 10 Replies

Depends on what you want Serkan.
This http://www.daniweb.com/code/snippet1022.html loops through what is called the KnowColors.
All the colors would need 256*256*256 iterations I guess.

i dont have knowncolor, i am using on compact framework. i have System.Drawing.Color struct. and i has properties. i want to read those property values maybe using reflection.

You also could create a file and read it in.
One of the lines would be the values of this:

Color c = Color.CornflowerBlue;
            int Alpha = c.A;
            int Red = c.R;
            int Green = c.G;
            int Blue = c.B;

no, what i want is something simple, we have colors in System.Drawing.Color. all i want is to create a color picker.
I get angry when something gets hard for no reason as now.

what i want is something like this :

foreach(color c in system.drawing.color)
{
listviewitem lvi = new listviewitem(c.name);
lvi.forecolor = c;
}
it shouldnt be hard, should it?

i found this fucking thing :

foreach (PropertyInfo p in typeof(Color).GetProperties())
			{
				Color c = new Color();
				if (p.PropertyType == typeof(Color))
				{
					ListViewItem lvi = new ListViewItem(p.Name);
					lvi.ForeColor =(Color) p.GetValue(c,null);
					listView1.Items.Add(lvi);
				}
			}

Project is attached

How about a color wheel. The angle on the wheel is used to calculate the RGB required to display that color!

You select a ilumination level, 0.0=black 1.0=white, and then rotate through a 360 degree wheel at that luminance level!

i found this fucking thing :

foreach (PropertyInfo p in typeof(Color).GetProperties())
			{
				Color c = new Color();
				if (p.PropertyType == typeof(Color))
				{
					ListViewItem lvi = new ListViewItem(p.Name);
					lvi.ForeColor =(Color) p.GetValue(c,null);
					listView1.Items.Add(lvi);
				}
			}

Project is attached

Sir can u explain the ur code that how its work especially what is propertyinfo and what is its function.

Thanks in advance.

this is called reflection, you can search google with "c# reflection"
for further information.

Serkan, great example. I just noticed what is clearly a typo on your code. You want to iterate through the properties of the Colors (not Color) class. Maybe an edit would help people grasp this better. Thanks for the code. Helped.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of 1.21 million developers, IT pros, digital marketers, and technology enthusiasts learning and sharing knowledge.