0

Hey,
I'm trying to setup a combobox so a color selected will change the background.
I know I can name each color and direct it to the color by using -

private void button1_Click(object sender, EventArgs e)
        {
            string strColor = comboBox1.Text;
            Graphics g = this.CreateGraphics();
            switch (strColor)
            {
                {
                case "AliceBlue":
                    g.FillEllipse(new SolidBrush(Color.AliceBlue), 0, 0, 320, 220);
                    break;
  • and copy and paste changing the "AliceBlue" names for each color.
    but I'm sure there would be a way to borrow that name from the combobox.
    for instant 'in any case put that case as the color'...

any help would be greatly appreciated.

Edited by Nick Evan: Fixed formatting

3
Contributors
2
Replies
3
Views
7 Years
Discussion Span
Last Post by ddanbe
1
Color myColor = (Color)Enum.Parse(typeof(Color), <textfromcombobox>, true);

Enum.Parse take three parameters: The type, the text to convert and whether it should ignore case or not (true = ignore).

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.