1.11M Members

How to loop through colors?

 
0
 

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

 
0
 

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.

 
0
 

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.

 
0
 

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;
 
0
 

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.

 
0
 

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?

 
0
 

i found this ####ing 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

Attachments ColorPicker.zip (26.7KB)
Question Answered as of 4 Years Ago by ddanbe
 
0
 

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!

 
0
 

i found this ####ing 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.

 
0
 

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

 
0
 

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.

Isn't it about time forums rewarded their contributors?

Earn rewards points for helping others. Gain kudos. Cash out. Get better answers yourself.

It's as simple as contributing editorial or replying to discussions labeled or OP Kudos

You
This question has already been solved: Start a new discussion instead
Post:
Start New Discussion
Tags Related to this Article