Freigeben über


ColorTranslator.ToHtml-Methode

Übersetzt die angegebene Color-Struktur in die Zeichenfolgenentsprechung einer HTML-Farbe.

Namespace: System.Drawing
Assembly: System.Drawing (in system.drawing.dll)

Syntax

'Declaration
Public Shared Function ToHtml ( _
    c As Color _
) As String
'Usage
Dim c As Color
Dim returnValue As String

returnValue = ColorTranslator.ToHtml(c)
public static string ToHtml (
    Color c
)
public:
static String^ ToHtml (
    Color c
)
public static String ToHtml (
    Color c
)
public static function ToHtml (
    c : Color
) : String

Parameter

  • c
    Die zu übersetzende Color-Struktur.

Rückgabewert

Die Zeichenfolge, die die HTML-Farbe darstellt.

Hinweise

Diese Methode übersetzt eine Color-Struktur in die Zeichenfolgenentsprechung einer HTML-Farbe. Dies ist der allgemeine verwendete Name einer Farbe, z. B. "Red", "Blue" oder "Green", aber nicht die Zeichenfolgenentsprechung eines numerischen Farbwerts wie "FF33AA".

Beispiel

Das folgende Beispiel ist für die Verwendung mit Windows Forms vorgesehen und erfordert PaintEventArgse, wobei es sich um einen Parameter des Paint-Ereignishandlers handelt. Der Code übersetzt eine Color-Struktur in die Zeichenfolgenentsprechung einer HTML-Farbe und zeigt anschließend ein Meldungsfeld mit der resultierenden Zeichenfolge an.

Public Sub ToHtml_Example(ByVal e As PaintEventArgs)

    ' Create an instance of a Color structure.
    Dim myColor As Color = Color.Red

    ' Translate myColor to an HTML color.
    Dim htmlColor As String = ColorTranslator.ToHtml(myColor)

    ' Show a message box with the value of htmlColor.
    MessageBox.Show(htmlColor)
End Sub
public void ToHtml_Example(PaintEventArgs e)
{
    // Create an instance of a Color structure.
    Color myColor = Color.Red;
             
    // Translate myColor to an HTML color.
    string htmlColor = ColorTranslator.ToHtml(myColor);
             
    // Show a message box with the value of htmlColor.
    MessageBox.Show(htmlColor);
}
public:
   void ToHtml_Example( PaintEventArgs^ /*e*/ )
   {
      // Create an instance of a Color structure.
      Color myColor = Color::Red;

      // Translate myColor to an HTML color.
      String^ htmlColor = ColorTranslator::ToHtml( myColor );

      // Show a message box with the value of htmlColor.
      MessageBox::Show( htmlColor );
   }
public void ToHtml_Example(PaintEventArgs e)
{
    // Create an instance of a Color structure.
    Color myColor = Color.get_Red();

    // Translate myColor to an HTML color.
    String htmlColor = ColorTranslator.ToHtml(myColor);

    // Show a message box with the value of htmlColor.
    MessageBox.Show(htmlColor);
} //ToHtml_Example

Plattformen

Windows 98, Windows 2000 SP4, Windows Millennium Edition, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition

.NET Framework unterstützt nicht alle Versionen sämtlicher Plattformen. Eine Liste der unterstützten Versionen finden Sie unter Systemanforderungen.

Versionsinformationen

.NET Framework

Unterstützt in: 2.0, 1.1, 1.0

Siehe auch

Referenz

ColorTranslator-Klasse
ColorTranslator-Member
System.Drawing-Namespace