Converting Windows Forms Colors to Web RGB string values
On this page:
There are a couple of ways to do this:
string HeaderColor = "#" +
SystemColors.InactiveCaption.ToArgb().ToString("x").Substring(2);
The above is reliable for all situations. If you are using Web Colors on your Windows Forms you can get their names like this:
string Color = cd.Color.ToKnownColor().ToString();
Note that this basically returns the name of the color in the same way you see it in the IDE (in fact this is likely what the IDE uses to let you select the colors). This means if you use a non-Web color like the InactiveCaption color you get the name of the color ie. InactiveCaption. But if you choose something like BlueSteel the value will be returned as BlueSteel which works both in WinForms and the Web.
Other Posts you might also like
- Map Physical Paths with an HttpContext.MapPath() Extension Method in ASP.NET
- Getting the Client IP Address in ASP.NET Core
- Adding minimal OWIN Identity Authentication to an Existing ASP.NET MVC Application
- Preventing iOS Textbox Auto Zooming and ViewPort Sizing
- Adding Default Assemblies, Namespaces and Control Prefixes in Web.Config
The Voices of Reason
June 13, 2004
# re: Converting Windows Forms Colors to Web RGB string values
Thanks Gabe. Didn't know that one existed actually.
April 04, 2006
# re: Converting Windows Forms Colors to Web RGB string values
system.drawing.ColorTranslator.ToHtml(color) does not work the way I expected it to.
Response.Write(System.Drawing.ColorTranslator.ToHtml(Color.Red));
Displays 'Red' and not '#FF0000'
Not sure why
Response.Write(System.Drawing.ColorTranslator.ToHtml(Color.Red));
Displays 'Red' and not '#FF0000'
Not sure why
vijay kumar N
March 15, 2012
# re: Converting Windows Forms Colors to Web RGB string values
thanks Fluxtah.
ya it 's working..
ya it 's working..
# re: Converting Windows Forms Colors to Web RGB string values
system.drawing.ColorTranslator.ToHtml(color)