Set Windows Forms background color to hex value

I'm just trying to set the background of a Windows Forms window to a hex color value like "# 626262". I can't seem to find an easy way to do this. Is there an easy way to set the background color of a window shape?


source to share

2 answers

Hex values ​​are represented in C # for example 0x626262


So, you can just type this into the property editor.

If you want to do this at runtime, you can use ColorTranslator


myForm.BackColor =  ColorTranslator.FromHtml("#626262");




The ColorTranslator.FromHtml method converts the HTML color representation to a GDI + Color structure.

  • Create a string representation of the HTML color.
  • Convert htmlColor to GDI + Color structure.
  • Assign this color to your window shape background.


string hexColor = "#626262";

Color myColor = System.Drawing.ColorTranslator.FromHtml(hexColor);

form1.BackColor = myColor;




All Articles