15

I have one method named ChangeFormBackground(Color colorName) which changes the form background with the colorname which is the parameter of the method.Now when I call this method I have not color name but the hexadecimal code of the color and I want to change the background color of the form with that hexadecimal code using that method then what should I do?

Harikrishna
  • 4,185
  • 17
  • 57
  • 79

4 Answers4

36
using System.Windows.Media;
Color color = (Color)ColorConverter.ConvertFromString("#FFDFD991");

(this assumes an ARGB value)

or

Color color = System.Drawing.ColorTranslator.FromHtml("#FFCC66");
ZombieSheep
  • 29,603
  • 12
  • 67
  • 114
12

This will always work because it doesn't contain alpha color (which is not supported by BackColor property):

Color temp = Color.FromArgb(0xFF00FF);
Color result = Color.FromArgb(temp.R, temp.G, temp.B);
Webleeuw
  • 7,222
  • 33
  • 34
3

You could use the FromArgb method:

Color.FromArgb(0x78FF0000);
Darin Dimitrov
  • 1,023,142
  • 271
  • 3,287
  • 2,928
0

You can use ColorConverter Class for manipulating color representations.

Giorgi
  • 30,270
  • 13
  • 89
  • 125