进度条控件

当我们在做一个大大小小的项目的时候,可能会遇到显示一个进度或百分比的问题,如果只用一个数字表示给客户带来的是很死板的感觉。如果用一个进度条来表示就会使客户一目了然了,还很形象。
下面是我的进度条控件:

边框和颜色都可以设置,也可在后面显示100%
下面是部分源代码:
  1 /// <summary>
  2     ///作者:王永强|HeroBeast|海尔比斯特
  3     ///时间:2006-12-28
  4     ///功能:显示为一个进度条,可设置显示颜色等属性
  5     /// </summary>
  6     [DefaultProperty("Text"), 
  7         ToolboxData("<{0}:HBProcessBar runat=server></{0}:HBProcessBar>")]
  8     public class HBProcessBar : System.Web.UI.WebControls.WebControl
  9     {
 10         private int _iCurrentValue;
 11         
 12         //开发时间
 13         [
 14         Bindable(true),
 15         Category("HBProcessBar"),
 16         DefaultValue(""),
 17         Description("当前进度值")
 18         ]
 19         public int CurrentValue
 20         {
 21             get { return _iCurrentValue;  }
 22             set { _iCurrentValue = value; }
 23         }
 24         public override Unit Width
 25         {
 26             get
 27             {
 28                 return base.Width;
 29             }
 30             set
 31             {
 32                 base.Width = value;
 33             }
 34         }
 35         public override Unit Height
 36         {
 37             get
 38             {
 39                 return base.Height;
 40             }
 41             set
 42             {
 43                 base.Height = value;
 44             }
 45         }
 46 
 47 
 48         //
 49         public HBProcessBar()
 50         {
 51             _iCurrentValue = 0;
 52         }
 53         private bool _ShowPercent = true;
 54         [
 55         Bindable(true),
 56         Category("HBProcessBar"),
 57         DefaultValue(""),
 58         Description("是否显示100%")
 59         ]
 60         public bool ShowPercent
 61         {
 62             get { return _ShowPercent; }
 63             set { _ShowPercent = value;}
 64         }
 65         private string _borderColor = "#003300";
 66         [
 67         Bindable(true),
 68         Category("HBProcessBar"),
 69         DefaultValue(""),
 70         Description("边框颜色")
 71         ]
 72         public string BorderColors
 73         {
 74             get { return _borderColor ;}
 75             set { _borderColor = value;}
 76         }
 77         private string _border ="1";
 78         [
 79         Bindable(true),
 80         Category("HBProcessBar"),
 81         DefaultValue(""),
 82         Description("边框大小")
 83         ]
 84         public string Border
 85         {
 86             get { return _border; }
 87             set { _border = value;}
 88         }
 89 
 90         private string _StartColor = "green";
 91         [
 92         Bindable(true),
 93         Category("HBProcessBar"),
 94         DefaultValue(""),
 95         Description("渐变开始颜色")
 96         ]
 97         public string StartColor
 98         {
 99             get { return _StartColor ; }
100             set { _StartColor = value; }
101         }
102         private string _EndColor = "GhostWhite";
103         [
104         Bindable(true),
105         Category("HBProcessBar"),
106         DefaultValue(""),
107         Description("渐变结束颜色")
108         ]
109         public string EndColor
110         {
111             get { return _EndColor;}
112             set { _EndColor = value;}
113         }
114         /// <summary> 
115         /// 将此控件呈现给指定的输出参数。
116         /// </summary>
117         /// <param name="output"> 要写出到的 HTML 编写器 </param>
118         protected override void Render(HtmlTextWriter output)
119         {
120             output.Write("<TABLE  cellSpacing='0' cellPadding='0'  height='"+base.Height.ToString()+"'  border='"+this._border+"' borderColor='"+this._borderColor+"'>");
121             output.Write("<TR>");
122             output.Write("<TD width='"+base.Width.ToString()+"'>");
123                 
124             //正文开始
125 
126             output.Write("<TABLE  cellSpacing='0' cellPadding='0' width='"+base.Width.ToString()+"' border='0' height='"+base.Height.ToString()+"");
127             output.Write("<TR>");
128             output.Write("<TD>");
129             //第二个表
130             output.Write("<TABLE style='FILTER:progid:DXImageTransform.Microsoft.Gradient(GradientType=0, StartColorStr="+this._StartColor+", EndColorStr="+this._EndColor+" cellSpacing='0' cellPadding='0' width='"+_iCurrentValue.ToString()+"%' border='0' height='"+base.Height.ToString()+"' bgColor='red'>");
131             
132             output.Write("<TR><TD align='center'>"+_iCurrentValue.ToString()+"%"+"</TD></TR>");
133             
134             output.Write("</TABLE>");
135             //
136             output.Write("</TD>");
137             output.Write("</TR>");
138             output.Write("</TABLE>");
139             //正文结束
140             
141             output.Write("</TD>");
142             if(_ShowPercent)
143             {
144                 output.Write("<TD width='10'>");
145                 output.Write("100%");
146                 output.Write("</TD>");
147             }
148             output.Write("</TR>");
149             //
150             output.Write("</TABLE>");
151 
152         }
153     }

下面是源代码:
进度条控件源代码
希望大家批评指正。

原文地址:https://www.cnblogs.com/HeroBeast/p/656405.html