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

Ashley Medway
  • 7,151
  • 7
  • 49
  • 71
user2380844
  • 277
  • 4
  • 15
  • 30

3 Answers3

2

You can use the following:

bt_Save.BackColor = System.Drawing.ColorTranslator.FromHtml("#C9C9C9");
Jamie Dunstan
  • 3,725
  • 2
  • 24
  • 38
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);
Sajad Karuthedath
  • 14,987
  • 4
  • 32
  • 49
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

Vincent
  • 1,459
  • 15
  • 37