Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Changing background color of the form with hexadecimal code

Tags:

c#

.net

winforms

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?

like image 912
Harikrishna Avatar asked Feb 11 '10 09:02

Harikrishna


People also ask

How do I add background color to hexadecimal in HTML?

To add background color in HTML, use the CSS background-color property. Set it to the color name or code you want and place it inside a style attribute. Then add this style attribute to an HTML element, like a table, heading, div, or span tag.

How do I change the background color of a form?

Change the color, theme, or header imageIn Google Forms, open a form. Under "Color," you can choose a theme color and background color for your form. To add your own photo as a theme, under "Header," click Choose image.

What is the correct way of representing background color using hexadecimal in CSS?

Hexadecimal Color Values The most common way to specify colors in CSS is to use their hexadecimal (or hex) values. Hex values are actually just a different way to represent RGB values. Instead of using three numbers between 0 and 255, you use six hexadecimal numbers.

What is the code for 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).


2 Answers

using System.Windows.Media;
Color color = (Color)ColorConverter.ConvertFromString("#FFDFD991");

(this assumes an ARGB value)

or

Color color = System.Drawing.ColorTranslator.FromHtml("#FFCC66");
like image 165
ZombieSheep Avatar answered Sep 20 '22 20:09

ZombieSheep


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);
like image 25
Webleeuw Avatar answered Sep 20 '22 20:09

Webleeuw