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 Forms 使用,而且需要 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 色彩的字串表示。 這是色彩的常用名稱,例如 “Red”、“Blue” 或 “Green”,而不是數值色彩值的字串表示,例如 “FF33AA”。

適用於