网站首页
JSP空间
动态资讯
开源项目
技术文档
资源下载
J2EE资源
客户论坛
在线支付
 
  技术文档>>JAVA>>新手入门>>基础入门>查看文档  
  进度条web控件     
  文章作者:未知  文章来源:水木森林  
  查看:95次  录入:管理员--2007-11-17  
 


作者: 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>");
}
}
}
}
}

 
 
上一篇: eclipse 的字符串分区共享优化机制    下一篇: 开发eclipse下的自定义控件
  相关文档
为什么要自己写底层涵式? 11-17
j2ee开发n层应用 11-17
一个合格程序员该做的事情??你做好了吗 01-23
java开发框架:关于ssh架构的简单总结 05-08
sun重整旗鼓 软件开源收购三大主旋律 11-17
用javamail写简易电子邮件发送系统 11-17
javascript实现网页图片等比例缩放效果 06-26
基于.net的aop实现技术 11-17
下溯造型与运行期类型标识 11-17
什么时候在ejb系统中使用xml 11-17
visualcafe的主要工具介绍 11-17
用java从网上抓取指定url源码的方案 11-17
一种高效的javabea分页for sqlserver 11-17
java的网络功能与编程6 11-17
java更新xml的四种常用方法简介 11-16
jbuilder4入门(下) 11-17
在hibernate中获取数据方式与缓存使用 11-16
澄清 java 的接口与继承机制 11-17
jdbc编程基础第二部分 11-17
在java中对数组a[depth]的理解 11-17
返回首页 | 关于我们 | J网章程 | JSP空间合租 | 客服中心 | 免责声明 | 常见问题 | 参观机房
本站主机空间代理至厦门市华众网络科技有限公司
《中华人民共和国增值电信业务经营许可证》
编号:闽B2-20050079
@2005-2008福建JSP技术网 版权所有 闽ICP备05000928号
技术电话:13616026886
邮箱:admin@fjjsp.com 站长QQ,点击这里给我发消息