ColorTranslator.FromHtml-Methode
Übersetzt eine HTML-Farbdarstellung in eine GDI+-Color-Struktur.
Namespace: System.Drawing
Assembly: System.Drawing (in system.drawing.dll)
Syntax
'Declaration
Public Shared Function FromHtml ( _
htmlColor As String _
) As Color
'Usage
Dim htmlColor As String
Dim returnValue As Color
returnValue = ColorTranslator.FromHtml(htmlColor)
public static Color FromHtml (
string htmlColor
)
public:
static Color FromHtml (
String^ htmlColor
)
public static Color FromHtml (
String htmlColor
)
public static function FromHtml (
htmlColor : String
) : Color
Parameter
- htmlColor
Die Zeichenfolgenentsprechung der zu übersetzenden HTML-Farbe.
Rückgabewert
Die Color-Struktur, die die übersetzte HTML-Farbe darstellt.
Hinweise
Diese Methode übersetzt eine Zeichenfolgenentsprechung eines HTML-Farbnamens wie Blue oder Red in eine GDI+-Color-Struktur.
Beispiel
Das folgende Beispiel ist für die Verwendung mit Windows Forms vorgesehen und erfordert PaintEventArgse, wobei es sich um einen Parameter des Paint-Ereignishandlers handelt. Der Code übersetzt einen HTML-Farbnamen in eine Color-Struktur und füllt mit dieser Farbe ein Rechteck aus.
Public Sub FromHtml_Example(ByVal e As PaintEventArgs)
' Create a string representation of an HTML color.
Dim htmlColor As String = "Blue"
' Translate htmlColor to a GDI+ Color structure.
Dim myColor As Color = ColorTranslator.FromHtml(htmlColor)
' Fill a rectangle with myColor.
e.Graphics.FillRectangle(New SolidBrush(myColor), 0, 0, 100, 100)
End Sub
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->Graphics->FillRectangle( gcnew 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
Plattformen
Windows 98, Windows 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
.NET Framework unterstützt nicht alle Versionen sämtlicher Plattformen. Eine Liste der unterstützten Versionen finden Sie unter Systemanforderungen.
Versionsinformationen
.NET Framework
Unterstützt in: 2.0, 1.1, 1.0
Siehe auch
Referenz
ColorTranslator-Klasse
ColorTranslator-Member
System.Drawing-Namespace