1,105,290 Community Members

How to loop through colors?

serkan sendur
Postaholic
2,057 posts since Jan 2008
Reputation Points: 821 [?]
Q&As Helped to Solve: 129 [?]
Skill Endorsements: 1 [?]
Banned
 
0
 

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

Member Avatar
ddanbe
Posting Expert
5,335 posts since Oct 2008
Reputation Points: 2,054 [?]
Q&As Helped to Solve: 904 [?]
Skill Endorsements: 46 [?]
Featured
 
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.

serkan sendur
Postaholic
2,057 posts since Jan 2008
Reputation Points: 821 [?]
Q&As Helped to Solve: 129 [?]
Skill Endorsements: 1 [?]
Banned
 
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.

Member Avatar
ddanbe
Posting Expert
5,335 posts since Oct 2008
Reputation Points: 2,054 [?]
Q&As Helped to Solve: 904 [?]
Skill Endorsements: 46 [?]
Featured
 
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;
serkan sendur
Postaholic
2,057 posts since Jan 2008
Reputation Points: 821 [?]
Q&As Helped to Solve: 129 [?]
Skill Endorsements: 1 [?]
Banned
 
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.

serkan sendur
Postaholic
2,057 posts since Jan 2008
Reputation Points: 821 [?]
Q&As Helped to Solve: 129 [?]
Skill Endorsements: 1 [?]
Banned
 
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?

serkan sendur
Postaholic
2,057 posts since Jan 2008
Reputation Points: 821 [?]
Q&As Helped to Solve: 129 [?]
Skill Endorsements: 1 [?]
Banned
 
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
Member Avatar
wildgoose
Practically a Posting Shark
891 posts since Jun 2009
Reputation Points: 420 [?]
Q&As Helped to Solve: 102 [?]
Skill Endorsements: 0 [?]
 
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!

Member Avatar
qauaan
Newbie Poster
12 posts since May 2009
Reputation Points: 0 [?]
Q&As Helped to Solve: 0 [?]
Skill Endorsements: 0 [?]
 
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.

serkan sendur
Postaholic
2,057 posts since Jan 2008
Reputation Points: 821 [?]
Q&As Helped to Solve: 129 [?]
Skill Endorsements: 1 [?]
Banned
 
0
 

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

Mauricio Feijo
Newbie Poster
1 post since Feb 2013
Reputation Points: 0 [?]
Q&As Helped to Solve: 0 [?]
Skill Endorsements: 0 [?]
Unverified Member
 
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.

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