Solved

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

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

Is Your AD Toolbox Looking More Like a Toybox?

Managing Active Directory can get complicated.  Often, the native tools for managing AD are just not up to the task.  The largest Active Directory installations in the world have relied on one tool to manage their day-to-day administration tasks: Hyena. Start your trial today.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Greetings C# program 17 107
How can i use linq for parsing string datetime to real datetime? 16 45
.NET 2008 VB and C# 6 28
C# LINQ ForEach() question 6 28
Article by: Ivo
C# And Nullable Types Since 2.0 C# has Nullable(T) Generic Structure. The idea behind is to allow value type objects to have null values just like reference types have. This concerns scenarios where not all data sources have values (like a databa…
Introduction This article series is supposed to shed some light on the use of IDisposable and objects that inherit from it. In essence, a more apt title for this article would be: using (IDisposable) {}. I’m just not sure how many people would ge…
This Micro Tutorial will give you a basic overview how to record your screen with Microsoft Expression Encoder. This program is still free and open for the public to download. This will be demonstrated using Microsoft Expression Encoder 4.
The Email Laundry PDF encryption service allows companies to send confidential encrypted  emails to anybody. The PDF document can also contain attachments that are embedded in the encrypted PDF. The password is randomly generated by The Email Laundr…

832 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