颜色的转换工具|颜色的转换

更新时间:2013-12-25    来源:组件控件开发    手机版     字体:

【www.bbyears.com--组件控件开发】

上回我回复的看椰子林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不可能把一个颜色转换要自己写得这么麻烦。

本文来源:http://www.bbyears.com/asp/2959.html

猜你感兴趣