Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

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

Posted on 2010-09-12
4
Medium Priority
?
942 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
4 Comments
 
LVL 10

Accepted Solution

by:
james-ct16 earned 336 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 332 total points
ID: 33659627
0
 
LVL 10

Assisted Solution

by:joriszwaenepoel
joriszwaenepoel earned 332 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

On Demand Webinar: Networking for the Cloud Era

Ready to improve network connectivity? Watch this webinar to learn how SD-WANs and a one-click instant connect tool can boost provisions, deployment, and management of your cloud connection.

Question has a verified solution.

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

In order to hide the "ugly" records selectors (triangles) in the rowheaders, here are some suggestions. Microsoft doesn't have a direct method/property to do it. You can only hide the rowheader column. First solution, the easy way The first sol…
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…
This course is ideal for IT System Administrators working with VMware vSphere and its associated products in their company infrastructure. This course teaches you how to install and maintain this virtualization technology to store data, prevent vuln…
Want to learn how to record your desktop screen without having to use an outside camera. Click on this video and learn how to use the cool google extension called "Screencastify"! Step 1: Open a new google tab Step 2: Go to the left hand upper corn…

664 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