• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 332
  • Last Modified:

Iterate through Colors

Hi,

Can someone help me?  What I am trying to do is use a for each loop, to cycle through the System.Darwing.COlor collection, and populate a drop down list with each of there.

thanks in advance

Andrew
0
REA_ANDREW
Asked:
REA_ANDREW
  • 2
  • 2
1 Solution
 
Carl TawnSystems and Integration DeveloperCommented:
This:

            foreach (string s in Enum.GetNames(typeof(System.Drawing.KnownColor)))
                comboBox1.Items.Add(s);

Will give you a list of all known system colors. System.Drawing.Color is a struct rather than an enum, so you can't iterate over it.
0
 
REA_ANDREWAuthor Commented:
Ok I get no errors but the drop down list is empty

 foreach (string s in Enum.GetNames(typeof(KnownColor)))
       
        DropDownList1.Items.Add(s.ToString());

thanks

Andy
0
 
REA_ANDREWAuthor Commented:
I have at the top of my C# file

using System.Darwing;
using System.Drawing.Imaging;
0
 
Carl TawnSystems and Integration DeveloperCommented:
It should work ok. You don't need .ToString() after s in the Add line, but other than that it should be ok.

Try stepping through with the debugger and seeing what "s" is during the loop
0

Featured Post

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

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.

  • 2
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now