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.

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).

Take a look at this snippet, follow the instructions and it displays al the "KnownColors" together with their name.
You should also refresh the syntax of the switch-case statement. Read this this MSDN page as an example.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.