2012-05-17 120 views
5

我已經動態創建HyperLink。我想通過添加顏色代碼來改變顏色。ForeColor與代碼顏色

HyperLink hpl = new HyperLink(); 
hpl.Text = "SomeText"; 
hpl.ForeColor = "#5BB1E6"; 

//Cannot implicitly convert type 'string' to 'System.Drawing.Color 

但我不能。

如何添加代碼顏色到ForeColor

可能嗎?

+3

也許你需要[ 'ColorTranslator.FromHtml'](HTTP://msdn.microsof t.com/en-us/library/system.drawing.colortranslator.fromhtml.aspx) – V4Vendetta

+0

謝謝Mr. @ V4Vendetta – OammieR

回答

10

使用下面的代碼

HyperLink hpl = new HyperLink(); 
hpl.Text = "SomeText"; 
hpl.ForeColor = System.Drawing.ColorTranslator.FromHtml("#5BB1E6"); 
0

使用

hpl.ForeColor =System.Drawing.ColorTranslator.FromHtml("#5BB1E6"); 
0

你可以用下面的代碼,它可以幫助你

HyperLink hpl = new HyperLink(); 
hpl.Text = "SomeText"; 
//use this 
hpl.ForeColor = System.Drawing.Color.FromName("#5BB1E6") 

希望它有助於