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
2010-02-11 09:19:05
Thanks for the answer
Harikrishna
2010-02-11 12:06:03
A:
You can use ColorConverter Class for manipulating color representations.
Giorgi
2010-02-11 09:19:47
A:
You could use the FromArgb method:
Color.FromArgb(0x78FF0000);
Darin Dimitrov
2010-02-11 09:20:39
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
2010-02-11 09:27:14