0

I am setting the background color of a button from c#,

  bt_Save.BackColor=Color.Gray;
  bt_Submit.BackColor = Color.Gray;

but i dont want the grey color i want the #c9c9c9 color, i tried Color.#c9c9c9 it keeps showing error.. how to set the color

1
  • i have found the answer bt_Save.Attributes.CssStyle.Add("BACKGROUND-COLOR", "#FF5050"); Commented Jan 21, 2014 at 9:16

3 Answers 3

2

You can use the following:

bt_Save.BackColor = System.Drawing.ColorTranslator.FromHtml("#C9C9C9");
Sign up to request clarification or add additional context in comments.

Comments

2

Refer http://msdn.microsoft.com/en-us/library/system.drawing.colortranslator.fromhtml(v=vs.110).aspx

Use

  bt_Save.BackColor= System.Drawing.ColorTranslator.FromHtml("#C9C9C9");

Translates an HTML color representation to a GDI+ Color structure

OR

you can also use

bt_Save.BackColor = System.Drawing.Color.FromArgb(0xC9C9C9);

Comments

1

You could use the following:

System.Drawing.Color myColor = System.Drawing.Color.FromArgb(0xC9C9C9);
bt_Save.BackColor = myColor;
bt_Submit.BackColor = myColor;

Source: http://msdn.microsoft.com/en-us/library/2zys7833%28v=vs.110%29.aspx

3 Comments

Check the definition of the FromArgbmethod again. It doesn't support that "type" of input..
it show error that it has some invalid argument...
Corrected the answer, it was a type-o (or brainfart) on my part.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.