详细条WEB控件
2024年03月10日
使用系统;使用系统绘图;
使用系统.Web;
使用System.Web.UI;
使用System.Web.UI.WebControls;
使用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;
前景色=System.Drawing.Color.Blue;
边框颜色=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/值;
}
}
///<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=值;
}
}
}
///<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}?宽度={1}&高度={2}&百分比={3}&ForeColor={4}&BackColor={5}{6}'边框='0'宽度='{1}'高度='{2}'>",
ImageGeneratorUrl,
intWidth,
Height.ToString(),
百分比,
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(背景颜色)+"'><tr>");
int intCellWidth=intWidth/intCellCount;
int intCurPercentage=0;
int intPercentageStep=PercentageStep;
字符串strCellColor;
字符串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(前景色)+"'";
}
else
{
strCellColor="";
}
if(i==0)
{
输出.Write("<td height='"+Height+"'width='"+intCellWidth+"'"+strCellColor+">"+strCellValue+"</td>");
}
别的
{
输出.Write("<td width='"+intCellWidth+"'"+strCellColor+">"+strCellValue+"</td>");
}
}
输出.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+"'>");
输出.Write("<img src='"+BarImageUrl+"'width='"+intImageWidth+"'height='"+Height+"'>");
输出.Write("</td></tr></table>");
}
if(BorderColor!=Color.Empty)
{
输出.Write("</td></tr></table>");
}
}
}}
}