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

首頁 > 開發 > 綜合 > 正文

功能增強的進度條控件(源碼)

2024-07-21 02:24:07
字體:
來源:轉載
供稿:網友
因為比較簡單,也沒有多少技術含量,就把它帖出來,希望給別的朋友一點幫助 這個進度條控件,除了具有普通進度條的功能以外,還具有如下功能:設置進度條的背景色和前景色設置進度條的外觀方式(3d,single,none)是否自動顯示當前進度比例(比如在進度條的中間顯示當前進度58%)當然,這個功能還可以增加很多,比如背景色和前景色也可以用圖片代替,還有其它的功能打算在以后有時間時再添加,這次就寫這些了。代碼如下:

using system;

using system.collections;

using system.componentmodel;

using system.drawing;

using system.drawing.drawing2d ;

using system.data;

using system.windows.forms;

namespace xiaopang.windows

{

     /// <summary>

     /// gprogressbar 的摘要說明。

     /// </summary>

     public class gprogressbar : system.windows.forms.usercontrol

     {

         /// <summary>

         /// 必需的設計器變量。

         /// </summary>

         private system.componentmodel.container components = null;

 

         public gprogressbar()

         {

              // 該調用是 windows.forms 窗體設計器所必需的。

              initializecomponent();

              base.height = 23 ;

              this.resize+=new eventhandler(gprogressbar_resize);

              this.locationchanged+=new eventhandler(gprogressbar_resize);

         }

 

         private void gprogressbar_resize(object sender,system.eventargs e)

         {

              base.refresh() ;

         }

 

         private  int mmax =100;

         [browsable(true), description("最大值"), category("xiaopang")]

         public int max

         {

              get

              {

                   return mmax ;

              }

 

              set

              {

                   mmax = value > 0?value:1;

              }

         }

        

         [browsable(true), description("大小"), category("xiaopang")]

          public new size size

         {

 

              get

              {

                   return base.size ;

              }

 

              set

              {

                   base.size = value ;

              }

         }

         private  int mmin =0;

         [browsable(true), description("最小值"), category("xiaopang")]

         public int min

         {

              get

              {

                   return mmin ;

              }

 

              set

              {

                   mmin = value ;

              }

         }

 

         private int mstep = 1 ;

         [browsable(true), description("步長"), category("xiaopang")]

         public int step

         {

              get

              {

                   return mstep ;

              }

 

              set

              {

                   mstep = value ;

              }

        

         }

             

         [browsable(true), description("背景色"), category("xiaopang")]

         public override color backcolor

         {

 

              get

              {

                   return base.backcolor ;

              }

 

              set

              {

                   base.backcolor = value ;

              }

         }

         [browsable(true), description("前景色"), category("xiaopang")]

         public override color forecolor

         {

 

              get

              {

                   return base.forecolor ;

              }

 

              set

              {

                   base.forecolor = value ;

              }

         }

         private bool mrate = false;

         [browsable(true), description("是否顯示比例數字"), category("xiaopang")]

         public bool rate

         {

              get

              {

                   return mrate ;

              }

 

              set

              {

                   mrate = value ;

              }

         }

         private int mvalue = 0 ;

         [browsable(true), description("當前值"), category("xiaopang")]

         public int value

         {

              get

              {

                   return mvalue ;

              }

              set

              {

                   if (value <= this.max)

                    mvalue = value ;

                   else

                       mvalue = this.max ;

                   this.refresh() ;

              }

         }

 

 

         private borderstyle mborderstyle = borderstyle.fixed3d ;

         [defaultvalue(0), category("xiaopang"),description("外觀")]

         public borderstyle borderstyle

         {

              get

              {

                   return this.mborderstyle;

              }

              set

              {

                   if (this.mborderstyle != value)

                   {

                       this.mborderstyle = value;

                       this.refresh() ;

                   }

              }

         }

 

         public void performstep()

         {

              value++ ;

         }

 

         private void drawprogress(graphics g,rectangle rect)

         {

              int iwidth = (value*rect.width)/max ;

              rectangle drawrect = new rectangle(rect.x,rect.y,iwidth,rect.height) ;

              solidbrush front = new solidbrush(this.forecolor) ;

              g.fillrectangle(front,drawrect);    

              if (rate)

              {

                   int irate = value*100/max ;

                   string strtext = irate.tostring() + "%" ;

                   int itextwidth = (int)g.measurestring(strtext,this.font).width ;

                   int istart = rect.left + (rect.width - itextwidth)/2 ;          

                   point poss = new point(istart -10,rect.top) ;

                   point pose = new point(istart + itextwidth + 10,rect.bottom) ;

                   lineargradientbrush textbrush = new lineargradientbrush(poss,pose,this.backcolor,this.forecolor) ;

                   g.drawstring(strtext,this.font,textbrush,istart ,rect.top+5) ;

              }            

         }

 

         protected override void onpaintbackground(painteventargs pevent)

         {

              solidbrush back = new solidbrush(this.backcolor) ;

              pevent.graphics.fillrectangle(back,pevent.cliprectangle);   

         }

 

         protected override void onpaint(painteventargs e)

         {

              if (!this.designmode)

                drawprogress(e.graphics,e.cliprectangle) ;

             

              switch(borderstyle)

              {

                   case borderstyle.none:

                       break ;

                   case borderstyle.fixedsingle:

                       system.windows.forms.controlpaint.drawborder3d(e.graphics,e.cliprectangle,border3dstyle.flat) ;

                       break ;

                   case borderstyle.fixed3d:

                       system.windows.forms.controlpaint.drawborder3d(e.graphics,e.cliprectangle,border3dstyle.sunken) ;

                       break ;

              }

         }

 

         /// <summary>

         /// 清理所有正在使用的資源。

         /// </summary>

         protected override void dispose( bool disposing )

         {

              if( disposing )

              {

                   if(components != null)

                   {

                       components.dispose();

                   }

              }

              base.dispose( disposing );

         }

 

         #region 組件設計器生成的代碼

         /// <summary>

         /// 設計器支持所需的方法 - 不要使用代碼編輯器

         /// 修改此方法的內容。

         /// </summary>

         private void initializecomponent()

         {

              //

              // gprogressbar

              //

              this.name = "gprogressbar";

              this.size = new system.drawing.size(150, 24);

 

         }

         #endregion

     }

}

 

發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 忻城县| 芜湖县| 镇安县| 社旗县| 内黄县| 河曲县| 广州市| 曲周县| 建宁县| 尼勒克县| 贵溪市| 庄河市| 犍为县| 于都县| 玉树县| 明星| 灵丘县| 青海省| 保靖县| 江口县| 麦盖提县| 卢龙县| 金湖县| 青龙| 娄烦县| 湛江市| 寻乌县| 宁国市| 六盘水市| 德江县| 婺源县| 治县。| 稷山县| 宁乡县| 安塞县| 普陀区| 榆中县| 嘉定区| 通城县| 专栏| 南郑县|