国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 學院 > 開發設計 > 正文

進度條WEB控件

2019-11-18 15:13:15
字體:
來源:轉載
供稿:網友


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



發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 东乡族自治县| 莆田市| 遂昌县| 禄丰县| 井冈山市| 渑池县| 霍城县| 天津市| 木里| 邵阳县| 盐津县| 襄垣县| 张掖市| 福清市| 蒙山县| 尼勒克县| 进贤县| 剑川县| 茶陵县| 千阳县| 潞西市| 三原县| 临澧县| 酒泉市| 吉水县| 闽侯县| 白银市| 会宁县| 化德县| 上高县| 潢川县| 岳普湖县| 东港市| 平遥县| 天水市| 潮安县| 杭锦后旗| 九寨沟县| 康保县| 大名县| 永安市|