Solved

System.Drawing.Color add all to list (C#)

Posted on 2010-09-12
4
932 Views
Last Modified: 2012-05-10
Hello,

Need to store colors in a list for a radar chart.  The number of series are unknown, want to loop through the colors list to assign a color to each series plotted.

Can't find how to get all colors of System.Drawing.Color to add it to a list.  

List<string> colors = System.Drawing.Color<?>

AC.
0
Comment
Question by:AndyC1000
4 Comments
 
LVL 10

Accepted Solution

by:
james-ct16 earned 84 total points
ID: 33659231
Howdy
I dare say there is a neater way to do this, but off the top of my head here is one approach. All we do is reflect all the properties contained within the sctruct color and look for the colors contained within.

I hope that helps

James

            List<string> colours = new List<string>();
            PropertyInfo[] propertyInfos;
            propertyInfos = typeof(Color).GetProperties(BindingFlags.Static | BindingFlags.Public);
            foreach (PropertyInfo pi in propertyInfos)
            {
                if (pi.ReflectedType == typeof(Color))
                {
                    colours.Add(pi.Name);
                }
            }

Open in new window

0
 

Author Comment

by:AndyC1000
ID: 33659350
I tried to get the example working and realised the list should be of type System.Drawing.Color or am I accessing it incorrectly.  

[code]

for(int i = 0; i < list.Count; i++){ // contains the number of series.

string str = "series" + i;
for(int j = 0; j < colours.Count; j++){

System.Windows.Forms.DataVisualization.Charting.series series str = new System.Windows.Forms.DataVisualization.Charting.series()
series.Color = // colours[i];??

}

}
[/code]

There's also a problem with syntax in these two lines, conflicting local variables.
string str = "series" + i;
System.Windows.Forms.DataVisualization.Charting.series series str = new .....

0
 
LVL 29

Assisted Solution

by:Kumaraswamy R
Kumaraswamy R earned 83 total points
ID: 33659627
0
 
LVL 10

Assisted Solution

by:joriszwaenepoel
joriszwaenepoel earned 83 total points
ID: 33659773
You can get the names of an Enum with Enu.GetValues:

var colorNames = Enum.GetNames(typeof(System.Drawing.KnownColor));
0

Featured Post

Free Tool: Postgres Monitoring System

A PHP and Perl based system to collect and display usage statistics from PostgreSQL databases.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article describes a simple method to resize a control at runtime.  It includes ready-to-use source code and a complete sample demonstration application.  We'll also talk about C# Extension Methods. Introduction In one of my applications…
This article introduced a TextBox that supports transparent background.   Introduction TextBox is the most widely used control component in GUI design. Most GUI controls do not support transparent background and more or less do not have the…
Nobody understands Phishing better than an anti-spam company. That’s why we are providing Phishing Awareness Training to our customers. According to a report by Verizon, only 3% of targeted users report malicious emails to management. With compan…

830 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question