繁体中文
设为首页
加入收藏
当前位置:.Net技术首页 >> 组件控件开发 >> 嘿嘿。好东西呀。。。让大家都来看看。我没有睡觉的结果。

嘿嘿。好东西呀。。。让大家都来看看。我没有睡觉的结果。

2004-10-01 08:26:10  作者:  来源:互联网  浏览次数:15  文字大小:【】【】【
简介:using System; using System.Drawing; using System.Web; using System.Web.UI; using System.Web.UI.WebControls; using System.ComponentModel; namespace Blood.Com.WebControl {     /...
关键字:嘿嘿 东西 结果 大家

using System;

using System.Drawing;

using System.Web;

using System.Web.UI;

using System.Web.UI.WebControls;

using System.ComponentModel;

namespace Blood.Com.WebControl

{

///

/// 进度条WEB控件

///

[DefaultProperty("Text"),

ToolboxData("<{0}:ProgressBar runat=server>")]

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("

");

}

else

{

output.Write("

");

}

}

output.Write("

" + strCellValue + " " + strCellValue + "
");

}

else

{

int intImageWidth = (int)((intPercentage / 100.0) * intWidth);

output.Write("
");

output.Write("");

output.Write("

");

}

if (BorderColor != Color.Empty)

{

output.Write("

");

}

}

}

}

}

责任编辑:admin
相关文章