tags:

views:

171

answers:

4

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?

+3  A: 
using System.Windows.Media;
Color color = (Color)ColorConverter.ConvertFromString("#FFDFD991");

(this assumes an ARGB value)

or

Color color = System.Drawing.ColorTranslator.FromHtml("#FFCC66");
ZombieSheep
Thanks for the answer
Harikrishna
A: 

You can use ColorConverter Class for manipulating color representations.

Giorgi
Thanks for the answer
Harikrishna
A: 

You could use the FromArgb method:

Color.FromArgb(0x78FF0000);
Darin Dimitrov
Mind that a Form.BackColor doesn't support alpha / transparancy
Webleeuw
Thanks for the answer
Harikrishna
A: 

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
Thanks for the answer
Harikrishna