作者: 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
http://www.gaodaima.com/64861.html进度条WEB控件_java
{
///
/// 进度条WEB控件
///
[DefaultProperty("Text"),
ToolboxData("{0}:ProgressBar>")]
public class ProgressBar : System.Web.UI.WebControls.WebControl
{
//声明变量
///
/// 进度条百分比
///
private int intPercentage = 0;
///
/// 列数
///
private int intCellCount = 20;
///
/// 填充图片网址
///
private string strFillImageUrl = "";
///
/// 进度条图片网址
///
private string strBarImageUrl = "";
///
/// 图片发生器网址
///
private string strImageGeneratorUrl = "";
///
/// 构造函数
///
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);
}
///
/// 进度条百分比步幅
///
public int PercentageStep
{
get{return 100 / intCellCount;}
set
{
if((100 % value) != 0)
{
throw new ArgumentException("百分比步副必须被100整除");
}
intCellCount = 100 / value;
}
}
///
/// 填充图片网址
///
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;}
}
///
/// 设置进度条百分比
///
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;
}
}
}
///
/// 进度条输出参数
///
/// 进度条
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("",
ImageGeneratorUrl,
intWidth,
Height.ToString(),
Percentage,
ColorTranslator.ToHtml(ForeColor),
ColorTranslator.ToHtml(BackColor),
strBorderColor));
}
else
{
if (BorderColor != Color.Empty)
{
output.Write("
"); } if (BarImageUrl == "") { output.Write(" int intCellWidth = intWidth / intCellCount; int intCurPercentage = 0; int intPercentageStep = PercentageStep; string strCellColor; string strCellValue = ""; if (Page.Request.Browser.Browser.ToUpper() == "NETSCAPE") { if (FillImageUrl != "") { strCellValue = " } 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(" | " + strCellValue + " |
}
else
{
output.Write("
" + strCellValue + "");}
}
output.Write("
");}
else
{
int intImageWidth = (int)((intPercentage / 100.0) * intWidth);
output.Write("
"); output.Write(" output.Write(" |
}
if (BorderColor != Color.Empty)
{
output.Write("
");}
}
}
}
}
欢迎大家阅读《进度条WEB控件_java》,跪求各位点评,若觉得好的话请收藏本文,by 搞代码
原创文章,转载请注明: 转载自搞代码
微信 赏一包辣条吧~
支付宝 赏一听可乐吧~