ColorTranslator.FromHtml(String) Metod

Definition

Översätter en HTML-färgrepresentation till en 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

Parametrar

htmlColor
String

Strängrepresentationen av html-färgen som ska översättas.

Returer

Strukturen Color som representerar den översatta HTML-färgen eller Empty om htmlColor är null.

Undantag

htmlColor är inte ett giltigt HTML-färgnamn.

Exempel

Följande exempel är utformat för användning med Windows Forms och kräver PaintEventArgse, vilket är en parameter för händelsehanteraren Paint. Koden översätter ett HTML-färgnamn till en Color struktur och använder sedan den färgen för att fylla en rektangel.

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

Kommentarer

Den här metoden översätter en strängrepresentation av ett HTML-färgnamn, till exempel Blått eller Rött, till en GDI+ Color -struktur.

Gäller för