Solved

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

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

[Webinar] How Hackers Steal Your Credentials

Do You Know How Hackers Steal Your Credentials? Join us and Skyport Systems to learn how hackers steal your credentials and why Active Directory must be secure to stop them. Thursday, July 13, 2017 10:00 A.M. PDT

Question has a verified solution.

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

This article aims to explain the working of CircularLogArchiver. This tool was designed to solve the buildup of log file in cases where systems do not support circular logging or where circular logging is not enabled
The article shows the basic steps of integrating an HTML theme template into an ASP.NET MVC project
Monitoring a network: why having a policy is the best policy? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the enormous benefits of having a policy-based approach when monitoring medium and large networks. Software utilized in this v…
Sometimes it takes a new vantage point, apart from our everyday security practices, to truly see our Active Directory (AD) vulnerabilities. We get used to implementing the same techniques and checking the same areas for a breach. This pattern can re…

617 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