| |
作者: blood
using system; using system.drawing; using system.web; using system.web.ui; using system.web.ui.webcontrols; using system.componentmodel;
namespace blood.com.webcontrol { /// <summary> /// 进度条web控件 /// </summary> [defaultproperty("text"), toolboxdata("<{0}:progressbar runat=server></{0}:progressbar>")] public class progressbar : system.web.ui.webcontrols.webcontrol { //声明变量
/// <summary> /// 进度条百分比 /// </summary> private int intpercentage = 0; /// <summary> /// 列数 /// </summary> private int intcellcount = 20; /// <summary> /// 填充图片网址 /// </summary> private string strfillimageurl = ""; /// <summary> /// 进度条图片网址 /// </summary> private string strbarimageurl = ""; /// <summary> /// 图片发生器网址 /// </summary> private string strimagegeneratorurl = "";
/// <summary> /// 构造函数 /// </summary> public progressbar() { // 初始化进度条的背景颜色、字体颜色和边框颜色 backcolor = system.drawing.color.lightgray; forecolor = system.drawing.color.blue; bordercolor = color.empty;
//初始化进度条的宽度和高度 base.width = unit.pixel(100); base.height = unit.pixel(16); }
/// <summary> /// 进度条百分比步幅 /// </summary> public int percentagestep { get{return 100 / intcellcount;} set { if((100 % value) != 0) { throw new argumentexception("百分比步副必须被100整除"); } intcellcount = 100 / value; } }
/// <summary> /// 填充图片网址 /// </summary> public string fillimageurl { get{return strfillimageurl;} set{strfillimageurl = value;} }
public string barimageurl { get{return strbarimageurl;} set{strbarimageurl = value;} }
public string imagegeneratorurl { get{return strimagegeneratorurl;} set{strimagegeneratorurl = value;} }
/// <summary> /// 设置进度条百分比 /// </summary> public int percentage { get {return intpercentage;} set { // 确定百分比在指定的范围内 // if (value > 100) // 超过100则显示100 { intpercentage = 100; } else if (value < 0) // 小于0则显示0 { intpercentage = 0; } else { intpercentage = value; } } }
/// <summary> /// 进度条输出参数 /// </summary> /// <param name="output"> 进度条 </param> protected override void render(htmltextwriter output) { if (width.type != unittype.pixel) { throw new argumentexception("宽度必须为象素"); }
int intwidth = (int)width.value;
if (imagegeneratorurl != "") { string strbordercolor = ""; if (bordercolor != color.empty) { strbordercolor = "&bordercolor=" + colortranslator.tohtml(bordercolor); }
output.write(string.format("<img src='{0}?width={1}&height={2}&percentage={3}&forecolor={4}&backcolor={5}{6}' border='0' width='{1}' height='{2}'>", imagegeneratorurl, intwidth, height.tostring(), percentage, colortranslator.tohtml(forecolor), colortranslator.tohtml(backcolor), strbordercolor)); } else { if (bordercolor != color.empty) { output.write("<table border='0' cellspacing='0' cellpadding='1' bgcolor='" + colortranslator.tohtml(bordercolor) + "'><tr><td>"); } if (barimageurl == "") { output.write("<table border='0' cellspacing='0' cellpadding='0' height='" + height + "' bgcolor='" + colortranslator.tohtml(backcolor) + "'><tr>"); int intcellwidth = intwidth / intcellcount; int intcurpercentage = 0; int intpercentagestep = percentagestep; string strcellcolor; string strcellvalue = "";
if (page.request.browser.browser.toupper() == "netscape") { if (fillimageurl != "") { strcellvalue = "<img src='" + fillimageurl + "' border='0' width='" + intcellwidth + "'>"; } else { strcellvalue = " "; } } for (int i = 0; i < intcellcount; i++, intcurpercentage += intpercentagestep) { if (intcurpercentage < intpercentage) { strcellcolor = " bgcolor='" + colortranslator.tohtml(forecolor) + "'"; } else { strcellcolor = ""; }
if (i == 0) { output.write("<td height='" + height + "' width='" + intcellwidth + "'" + strcellcolor + ">" + strcellvalue + "</td>"); } else { output.write("<td width='" + intcellwidth + "'" + strcellcolor + ">" + strcellvalue + "</td>"); } } output.write("</tr></table>"); } else { int intimagewidth = (int)((intpercentage / 100.0) * intwidth);
output.write("<table border='0' cellpadding='0' cellspacing='0' bgcolor='" + colortranslator.tohtml(backcolor) + "'><tr><td width='" + intwidth + "'>"); output.write("<img src='" + barimageurl + "' width='" + intimagewidth + "' height='" + height + "'>"); output.write("</td></tr></table>"); } if (bordercolor != color.empty) { output.write("</td></tr></table>"); } } } } }
|
|