ColorTranslator.FromHtml(String) Metoda
Definicja
Ważne
Niektóre informacje odnoszą się do produktu w wersji wstępnej, który może zostać znacząco zmodyfikowany przed wydaniem. Firma Microsoft nie udziela żadnych gwarancji, jawnych lub domniemanych, w odniesieniu do informacji podanych w tym miejscu.
Tłumaczy reprezentację koloru HTML na strukturę GDI+ Color.
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
Parametry
- htmlColor
- String
Reprezentacja ciągu koloru HTML do tłumaczenia.
Zwraca
Struktura Color reprezentująca przetłumaczony kolor HTML lub Empty, jeśli htmlColor jest null.
Wyjątki
htmlColor nie jest prawidłową nazwą koloru HTML.
Przykłady
Poniższy przykład jest przeznaczony do użycia z formularzami Systemu Windows i wymaga PaintEventArgse, który jest parametrem programu obsługi zdarzeń Paint. Kod tłumaczy nazwę koloru HTML na strukturę Color, a następnie używa tego koloru do wypełnienia prostokąta.
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
Uwagi
Ta metoda tłumaczy reprezentację ciągu nazwy koloru HTML, takiej jak Blue lub Red, na strukturę GDI+ Color.