Freigeben über


ColorTranslator.FromHtml(String) Methode

Definition

Übersetzt eine HTML-Farbdarstellung in eine GDI+-Color-Struktur.

public:
 static System::Drawing::Color FromHtml(System::String ^ htmlColor);
public static System.Drawing.Color FromHtml (string htmlColor);
static member FromHtml : string -> System.Drawing.Color
Public Shared Function FromHtml (htmlColor As String) As Color

Parameter

htmlColor
String

Die Zeichenfolgenentsprechung der zu übersetzenden HTML-Farbe.

Gibt zurück

Die Color-Struktur, die die übersetzte HTML-Farbe darstellt oder Empty, wenn htmlColor den Wert null hat.

Ausnahmen

htmlColor ist kein gültiger HTML-Farbname.

Beispiele

Das folgende Beispiel ist für die Verwendung mit Windows Forms konzipiert und erfordert PaintEventArgse, was ein Parameter des Paint Ereignishandlers ist. Der Code übersetzt einen HTML-Farbnamen in eine Color Struktur und verwendet diese Farbe dann, um ein Rechteck zu füllen.

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.Graphics.FillRectangle( new SolidBrush(myColor), 0, 0, 
        100, 100);
}
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

Hinweise

Diese Methode übersetzt eine Zeichenfolgendarstellung eines HTML-Farbnamens, z. B. Blau oder Rot, in eine GDI+ Color -Struktur.

Gilt für: