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”。
适用于
反馈
https://aka.ms/ContentUserFeedback。
即将发布:在整个 2024 年,我们将逐步淘汰作为内容反馈机制的“GitHub 问题”,并将其取代为新的反馈系统。 有关详细信息,请参阅:提交和查看相关反馈