颜色的转换

来源:互联网 发布:高斯平滑算法 编辑:程序博客网 时间:2024/04/16 19:26

上回我回复的看椰子林DotNet的天空-----ASP.NET组件编程step by step-------------------
# 回复:有点小BUG
//以下将颜色值转化成十六进制表示
string R,G,B;
R = (Convert.ToInt32(this._backgroundColor.R)).ToString("X");
G = (Convert.ToInt32(this._backgroundColor.G)).ToString("X");
B = (Convert.ToInt32(this._backgroundColor.B)).ToString("X");
if(R.Length==1)R = "0" + R;
if(G.Length==1)G = "0" + G;
if(B.Length==1)B = "0" + B;
-----------------------------------

其实以下代码可以换成一行代码就搞定--------------------
//以下将颜色值转化成十六进制表示
string R,G,B;

R = (Convert.ToInt32(this._backgroundColor.R)).ToString("X");

G = (Convert.ToInt32(this._backgroundColor.G)).ToString("X");

B = (Convert.ToInt32(this._backgroundColor.B)).ToString("X");

if(R.Length==1)
R = "0" + R;
if(G.Length==1)
G = "0" + G;
if(B.Length==1)
B = "0" + B;


Table t=(Table)Controls[i];

t.Attributes.Add("id",t.ClientID);

this.textBox.Attributes["onfocus"]="ltmouseover("+t.ClientID+",'" + "#" + R + G + B + "')";
--------改成-------------------------
this.textBox.Attributes.Add("onmouseover","ltmouseover(this,'" + ColorTranslator.ToHtml(this._mouseoverColor) + "')");

简单吧!无意中发现的!因为我想想MS不可能把一个颜色转换要自己写得这么麻烦。

原创粉丝点击