A
Adam Sandler
Hello:
I'm trying to iterate through an enum of Colors. I'll post a very
basic example of the code for clarity. Here's the declaration:
enum myColor { Red, Blue, Black };
For now, I just have a foreach inside a button event handler:
private void button3_Click(object sender, EventArgs e)
{
foreach (System.Drawing.Color c in Enum.GetNames(typeof
(myColor)))
{
this.BackColor = c;
}
}
This bit of code does not compile. I get an error on the foreach
which says "Cannot convert type 'string' to 'System.Drawing.Color'".
Okay... I kinda get it. But I'm also under the impression that I have
to use System.Enum to parse the collection... this will not work
either: foreach (System.Drawing.Color c in myColor)
So, the question is, how can I iterate through an enum of colors and
then use the results to assign to properties... re: the line
this.BackColor = c ???
Suggestions are greatly appreciated.
Thanks!
I'm trying to iterate through an enum of Colors. I'll post a very
basic example of the code for clarity. Here's the declaration:
enum myColor { Red, Blue, Black };
For now, I just have a foreach inside a button event handler:
private void button3_Click(object sender, EventArgs e)
{
foreach (System.Drawing.Color c in Enum.GetNames(typeof
(myColor)))
{
this.BackColor = c;
}
}
This bit of code does not compile. I get an error on the foreach
which says "Cannot convert type 'string' to 'System.Drawing.Color'".
Okay... I kinda get it. But I'm also under the impression that I have
to use System.Enum to parse the collection... this will not work
either: foreach (System.Drawing.Color c in myColor)
So, the question is, how can I iterate through an enum of colors and
then use the results to assign to properties... re: the line
this.BackColor = c ???
Suggestions are greatly appreciated.
Thanks!