• 欢迎访问搞代码网站,推荐使用最新版火狐浏览器和Chrome浏览器访问本网站!
  • 如果您觉得本站非常有看点,那么赶紧使用Ctrl+D 收藏搞代码吧

进度条WEB控件_java

java 搞代码 7年前 (2018-08-06) 171次浏览 已收录 0个评论

作者: 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

{
/// <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>");
}
}
}
}
}

欢迎大家阅读《进度条WEB控件_java,跪求各位点评,若觉得好的话请收藏本文,by 搞代码


搞代码网(gaodaima.com)提供的所有资源部分来自互联网,如果有侵犯您的版权或其他权益,请说明详细缘由并提供版权或权益证明然后发送到邮箱[email protected],我们会在看到邮件的第一时间内为您处理,或直接联系QQ:872152909。本网站采用BY-NC-SA协议进行授权
转载请注明原文链接:进度条WEB控件_java

喜欢 (0)
[搞代码]
分享 (0)
发表我的评论
取消评论

表情 贴图 加粗 删除线 居中 斜体 签到

Hi,您需要填写昵称和邮箱!

  • 昵称 (必填)
  • 邮箱 (必填)
  • 网址