Condividi tramite


ColorTranslator.FromHtml(String) Metodo

Definizione

Converte una rappresentazione di colore HTML in una struttura Color GDI+.

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

Parametri

htmlColor
String

Rappresentazione in forma di stringa del colore HTML da convertire.

Restituisce

Struttura Color che rappresenta il colore HTML convertito o Empty se htmlColor è null.

Eccezioni

htmlColor non è un nome di colore HTML valido.

Esempio

L'esempio seguente è progettato per l'uso con Windows Forms e richiede PaintEventArgse, che è un parametro del Paint gestore eventi. Il codice converte un nome di colore HTML in una Color struttura e quindi usa tale colore per riempire un rettangolo.

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

Commenti

Questo metodo converte una rappresentazione di stringa di un nome di colore HTML, ad esempio Blu o Rosso, in una struttura GDI+ Color .

Si applica a