ColorTranslator.ToHtml(Color) 方法

定義

將指定的 Color 結構轉換為 HTML 字串色彩表示。Translates the specified Color structure to an HTML string color representation.

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 結構。The Color structure to translate.

傳回

字串,表示 HTML 色彩。The string that represents the HTML color.

範例

下列範例是針對與 Windows Forms 搭配使用所設計, 而且它PaintEventArgs需要e, 這Paint是事件處理常式的參數。The following example is designed for use with Windows Forms, and it requires PaintEventArgse, which is a parameter of the Paint event handler. 程式碼Color會將結構轉譯為 HTML 色彩的字串標記法, 然後顯示含有所產生字串的訊息方塊。The code translates a Color structure to a string representation of an HTML color, and then shows a message box with the resulting string.

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 色彩的字串表示。This method translates a Color structure to a string representation of an HTML color. 這是色彩常用的名稱, 例如 "Red"、"Blue" 或 "綠", 而不是數值色彩值的字串標記法, 例如 "FF33AA"。This is the commonly used name of a color, such as "Red", "Blue", or "Green", and not string representation of a numeric color value, such as "FF33AA".

適用於