Solved

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

Posted on 2010-09-12
4
922 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

Find Ransomware Secrets With All-Source Analysis

Ransomware has become a major concern for organizations; its prevalence has grown due to past successes achieved by threat actors. While each ransomware variant is different, we’ve seen some common tactics and trends used among the authors of the malware.

Join & Write a Comment

Article by: Najam
Having new technologies does not mean they will completely replace old components.  Recently I had to create WCF that will be called by VB6 component.  Here I will describe what steps one should follow while doing so, please feel free to post any qu…
It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
Get a first impression of how PRTG looks and learn how it works.   This video is a short introduction to PRTG, as an initial overview or as a quick start for new PRTG users.
In this tutorial you'll learn about bandwidth monitoring with flows and packet sniffing with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're interested in additional methods for monitoring bandwidt…

743 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

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now