如何在vb.net中使用“#FFFF00”?

时间:2021-11-17 13:55:42

When I attempt to use label1.ForeColor="#FFFF00" I get an error: "Specified cast is not valid."

当我尝试使用label1.ForeColor =“#FFFF00”时,我收到一个错误:“指定的强制转换无效。”

How can I resolve this?

我该如何解决这个问题?

2 个解决方案

#1


3  

do like...

Label1.ForeColor = System.Drawing.Color.FromName("#FFFF00")

#2


3  

You can use the WebColorConverter class.

您可以使用WebColorConverter类。

It has a ConvertFromString method that can be used like this:

它有一个ConvertFromString方法,可以像这样使用:

Dim ColorString As String = "#FFFF00"
Dim Color_Converter As New ColorConverter
Dim ActualColor As Color = Color_Converter.ConvertFromString(ColorString)

#1


3  

do like...

Label1.ForeColor = System.Drawing.Color.FromName("#FFFF00")

#2


3  

You can use the WebColorConverter class.

您可以使用WebColorConverter类。

It has a ConvertFromString method that can be used like this:

它有一个ConvertFromString方法,可以像这样使用:

Dim ColorString As String = "#FFFF00"
Dim Color_Converter As New ColorConverter
Dim ActualColor As Color = Color_Converter.ConvertFromString(ColorString)