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?
Asked
Active
Viewed 5.3k times
4 Answers
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
-
Which alpha does `Color.FromArgb(0xFF00FF);` use? – Anders Lindén Jun 03 '17 at 22:50
3
You could use the FromArgb method:
Color.FromArgb(0x78FF0000);

Darin Dimitrov
- 1,023,142
- 271
- 3,287
- 2,928