I am simply trying to set the background of a Windows Forms window to a hex color value, eg, "#626262." I cannot seem to find any simple way to do it. Is there a simple way to set the background color of a windows form?
Set the background in the Windows Forms DesignerSelect the Custom tab to display a palette of colors. Select the Web or System tab to display a list of predefined names for colors, and then select a color.
Background-color values can be expressed in hexadecimal values such as #FFFFFF, #000000, and #FF0000. Background-color values can be expressed using rgb such as rgb(255,255,255), rgb(0,0,0), and rgb(255,0,0). Background-color values can be expressed as named colors such as white, black, and red.
A hex code is a 3-byte hexadecimal number used in HTML, CSS, and other applications to represent colors. They will start with a hashtag (#) and are followed by 6 digits, using either numbers, letters (A - F), or a combination of both.
Hex values are represented in C# like 0x626262
.
So you can simply enter that into the property editor.
If you want to do it at runtime, you can use ColorTranslator
:
myForm.BackColor = ColorTranslator.FromHtml("#626262");
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With