ColorTranslator.FromHtml(String) 方法
定义
重要
一些信息与预发行产品相关,相应产品在发行之前可能会进行重大修改。 对于此处提供的信息,Microsoft 不作任何明示或暗示的担保。
将 HTML 颜色表示形式翻译成 GDI+ Color 结构。
public:
static System::Drawing::Color FromHtml(System::String ^ htmlColor);
public static System.Drawing.Color FromHtml (string htmlColor);
static member FromHtml : string -> System.Drawing.Color
Public Shared Function FromHtml (htmlColor As String) As Color
参数
- htmlColor
- String
要翻译的 Html 颜色的字符串表示形式。
返回
表示已翻译的 HTML 颜色或 Color 的Empty 结构(如果 htmlColor
为 null
)。
例外
htmlColor
不是有效的 HTML 颜色名称。
示例
以下示例旨在与 Windows 窗体 一起使用,它需要 PaintEventArgse
,这是事件处理程序的参数Paint。 该代码将 HTML 颜色名称转换为 Color 结构,然后使用该颜色填充矩形。
public:
void FromHtml_Example( PaintEventArgs^ e )
{
// Create a string representation of an HTML color.
String^ htmlColor = "Blue";
// Translate htmlColor to a GDI+ Color structure.
Color myColor = ColorTranslator::FromHtml( htmlColor );
// Fill a rectangle with myColor.
e->Graphics->FillRectangle( gcnew SolidBrush( myColor ), 0, 0, 100, 100 );
}
public void FromHtml_Example(PaintEventArgs e)
{
// Create a string representation of an HTML color.
string htmlColor = "Blue";
// Translate htmlColor to a GDI+ Color structure.
Color myColor = ColorTranslator.FromHtml(htmlColor);
// Fill a rectangle with myColor.
e.Graphics.FillRectangle( new SolidBrush(myColor), 0, 0,
100, 100);
}
Public Sub FromHtml_Example(ByVal e As PaintEventArgs)
' Create a string representation of an HTML color.
Dim htmlColor As String = "Blue"
' Translate htmlColor to a GDI+ Color structure.
Dim myColor As Color = ColorTranslator.FromHtml(htmlColor)
' Fill a rectangle with myColor.
e.Graphics.FillRectangle(New SolidBrush(myColor), 0, 0, 100, 100)
End Sub
注解
此方法将 HTML 颜色名称(如 Blue 或 Red)的字符串表示形式转换为 GDI+ Color 结构。
适用于
反馈
https://aka.ms/ContentUserFeedback。
即将发布:在整个 2024 年,我们将逐步淘汰作为内容反馈机制的“GitHub 问题”,并将其取代为新的反馈系统。 有关详细信息,请参阅:提交和查看相关反馈