Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Set Windows Forms Background Color To Hex Value

Tags:

c#

winforms

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?

like image 906
Alex O'Brien Avatar asked Oct 03 '14 01:10

Alex O'Brien


People also ask

How do I change the background color in 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.

What is a hex background 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.

What is a hex code in forms?

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.


1 Answers

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");
like image 57
Blorgbeard Avatar answered Sep 30 '22 20:09

Blorgbeard