进度条WEB控件
2008-01-05 08:41:22 来源:WEB开发网
作者: 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>");
}
}
}
}
}
- ››WEBGAME龙虎榜,《传奇国度》成黑马
- ››WebQQ 2.0添加谷歌音乐方法
- ››WebLogic调整Java虚拟机性能优化参数
- ››webqq2.0协议研究(3)-ClientId生成
- ››Web.config配置文件
- ››WebBrowser组件的execWB方法——Delphi控制浏览器...
- ››Web前端设计模式--制作漂亮的弹出层
- ››WebSphere 反向投资者: 解决 WebSphere Applicati...
- ››WebSphere sMash 的创新应用,第 2 部分: 借助包装...
- ››WebQQ2.0怎样对话区域比例调节
- ››WebQQ2.0——QQ阅读&酷六视频上线
- ››Web安全网关 冠群金辰KILL过滤网关
赞助商链接