Share via


ColorTranslator.ToHtml(Color) 方法

定义

将指定的 Color 结构翻译成 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

参数

c
Color

要转换的 Color 结构。

返回

表示 HTML 颜色的字符串。

示例

以下示例旨在与 Windows 窗体 一起使用,它需要 PaintEventArgse,这是事件处理程序的参数Paint。 该代码将 Color 结构转换为 HTML 颜色的字符串表示形式,然后显示包含生成的字符串的消息框。

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

注解

此方法将 Color 结构转换为 HTML 颜色的字符串表示形式。 这是颜色的常用名称,例如“红色”、“蓝色”或“绿色”,而不是数字颜色值的字符串表示形式,例如“FF33AA”。

适用于