ColorTranslator.FromHtml(String) Methode

Definitie

Hiermee wordt een HTML-kleurweergave omgezet in een GDI+ Color -structuur.

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

Parameters

htmlColor
String

De tekenreeksweergave van de HTML-kleur die moet worden vertaald.

Retouren

De Color structuur die de vertaalde HTML-kleur vertegenwoordigt of Empty als htmlColor dat het is null.

Uitzonderingen

htmlColor is geen geldige HTML-kleurnaam.

Voorbeelden

Het volgende voorbeeld is ontworpen voor gebruik met Windows Forms en vereist PaintEventArgse, een parameter van de Paint gebeurtenis-handler. De code vertaalt een HTML-kleurnaam naar een Color structuur en gebruikt die kleur vervolgens om een rechthoek op te vullen.

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

Opmerkingen

Met deze methode wordt een tekenreeksweergave van een HTML-kleurnaam, zoals Blauw of Rood, omgezet in een GDI+ Color -structuur.

Van toepassing op