ColorTranslator.FromHtml(String) Método

Definición

Convierte la representación de un color HTML en una estructura Color de 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

Parámetros

htmlColor
String

Representación de cadena del color HTML que se va a convertir.

Devoluciones

Estructura Color que representa el color HTML convertido o Empty si htmlColor es null.

Excepciones

htmlColor no es un nombre de color HTML válido.

Ejemplos

El ejemplo siguiente está diseñado para su uso con Windows Forms y requiere PaintEventArgse, que es un parámetro del Paint controlador de eventos. El código traduce un nombre de color HTML a una Color estructura y, a continuación, usa ese color para rellenar un rectángulo.

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

Comentarios

Este método traduce una representación de cadena de un nombre de color HTML, como Azul o Rojo, a una estructura GDI+ Color .

Se aplica a