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 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”。
適用於
意見反應
https://aka.ms/ContentUserFeedback。
即將登場:在 2024 年,我們將逐步淘汰 GitHub 問題作為內容的意見反應機制,並將它取代為新的意見反應系統。 如需詳細資訊,請參閱:提交並檢視相關的意見反應