ColorTranslator.ToHtml(Color) Metod

Definition

Översätter den angivna Color strukturen till en HTML-strängfärgrepresentation.

public:
 static System::String ^ ToHtml(System::Drawing::Color c);
public static string ToHtml(System.Drawing.Color c);
static member ToHtml : System.Drawing.Color -> string
Public Shared Function ToHtml (c As Color) As String

Parametrar

c
Color

Strukturen Color som ska översättas.

Returer

Strängen som representerar HTML-färgen.

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 en Color struktur till en strängrepresentation av en HTML-färg och visar sedan en meddelanderuta med den resulterande strängen.

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 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

Kommentarer

Den här metoden översätter en Color struktur till en strängrepresentation av en HTML-färg. Det här är det vanliga namnet på en färg, till exempel "Röd", "Blå" eller "Grön", och inte strängrepresentation av ett numeriskt färgvärde, till exempel "FF33AA".

Gäller för