ColorTranslator.FromHtml Method
.NET Framework 2.0
Translates an HTML color representation to a GDI+ Color structure.
Namespace: System.Drawing
Assembly: System.Drawing (in system.drawing.dll)
Assembly: System.Drawing (in system.drawing.dll)
public static Color FromHtml ( String htmlColor )
public static function FromHtml ( htmlColor : String ) : Color
Not applicable.
Parameters
- htmlColor
The string representation of the Html color to translate.
Return Value
The Color structure that represents the translated HTML color or Empty if htmlColor is a null reference (Nothing in Visual Basic).The following example is designed for use with Windows Forms, and it requires PaintEventArgse, which is a parameter of the Paint event handler. The code translates an HTML color name to a Color structure, and then uses that color to fill a rectangle.
public void FromHtml_Example(PaintEventArgs e) { // Create a string representation of an HTML color. string htmlColor = "Blue"; // Translate htmlColor to a GDI+ Color structure. Color myColor = ColorTranslator.FromHtml(htmlColor); // Fill a rectangle with myColor. e.Graphics.FillRectangle( new SolidBrush(myColor), 0, 0, 100, 100); }
public void FromHtml_Example(PaintEventArgs e)
{
// Create a string representation of an HTML color.
String htmlColor = "Blue";
// Translate htmlColor to a GDI+ Color structure.
Color myColor = ColorTranslator.FromHtml(htmlColor);
// Fill a rectangle with myColor.
e.get_Graphics().FillRectangle(new SolidBrush(myColor), 0, 0, 100, 100);
} //FromHtml_Example
Windows 98, Windows Server 2000 SP4, Windows Millennium Edition, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition
The Microsoft .NET Framework 3.0 is supported on Windows Vista, Microsoft Windows XP SP2, and Windows Server 2003 SP1.