ColorTranslator.ToHtml(Color) Méthode

Définition

Convertit la structure Color spécifiée en représentation de couleur HTML de type chaîne.

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

Paramètres

c
Color

Structure Color à convertir.

Retours

Chaîne représentant la couleur HTML.

Exemples

L’exemple suivant est conçu pour être utilisé avec Windows Forms et nécessite PaintEventArgse, qui est un paramètre du Paint gestionnaire d’événements. Le code traduit une Color structure en une représentation sous forme de chaîne d’une couleur HTML, puis affiche une boîte de message avec la chaîne résultante.

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

Remarques

Cette méthode traduit une Color structure en une représentation sous forme de chaîne d’une couleur HTML. Il s’agit du nom couramment utilisé d’une couleur, telle que « Rouge », « Bleu » ou « Vert », et non de la représentation sous forme de chaîne d’une valeur de couleur numérique, telle que « FF33AA ».

S’applique à