ColorTranslator.ToHtml(Color) 方法
定義
重要
部分資訊涉及發行前產品,在發行之前可能會有大幅修改。 Microsoft 對此處提供的資訊,不做任何明確或隱含的瑕疵擔保。
將指定的 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
參數
傳回
代表 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」。