Sdílet prostřednictvím


ColorTranslator.ToHtml(Color) Metoda

Definice

Přeloží zadanou Color strukturu na barevnou reprezentaci řetězce HTML.

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

Parametry

c
Color

Struktura Color , která se má přeložit.

Návraty

Řetězec, který představuje barvu HTML.

Příklady

Následující příklad je určený pro použití s model Windows Forms a vyžaduje PaintEventArgse, což je parametr obslužné rutiny Paint události. Kód přeloží Color strukturu na řetězcovou reprezentaci barvy HTML a pak zobrazí okno se zprávou s výsledným řetězcem.

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

Poznámky

Tato metoda převede Color strukturu na řetězcovou reprezentaci barvy HTML. Toto je běžně používaný název barvy, například "Červená", "Modrá" nebo "Zelená", nikoli řetězcové vyjádření číselné hodnoty barvy, například "FF33AA".

Platí pro