自拍偷在线精品自拍偷,亚洲欧美中文日韩v在线观看不卡

C# listview進度條顯示淺析

開發(fā) 后端
C# listview進度條顯示是如何實現(xiàn)的呢?C# listview進度條顯示具體的實現(xiàn)需要注意什么方面呢?那么本文就向你介紹這方面的內容。

C# listview進度條顯示是如何實現(xiàn)的呢?讓我們來看看具體的實現(xiàn)過程。

程序比較簡單,就是重載了listview的實現(xiàn),不過很實用!

  1. using System;  
  2.  
  3. using System.Collections.Generic;  
  4.  
  5. using System.Text;  
  6.  
  7. using System.Windows.Forms;  
  8.  
  9. using System.Drawing;  
  10.  //C# listview進度條顯示
  11. namespace WindowsApplication1  
  12.  
  13. {  
  14.  
  15. class ListViewEx:System.Windows.Forms.ListView  
  16.  
  17. {  
  18.  
  19. public ListViewEx()  
  20.  
  21. {  
  22.  
  23. InitializeComponent();  
  24.  
  25. }  
  26.  
  27.  
  28.  //C# listview進度條顯示
  29. private Color mProgressColor = Color.Red;  
  30.  
  31. public Color ProgressColor  
  32.  
  33. {  
  34.  
  35. get 
  36.  
  37. {  
  38.  
  39. return this.mProgressColor;  
  40.  
  41. }  
  42.  
  43. set 
  44.  
  45. {  
  46.  
  47. this.mProgressColor = value;  
  48.  
  49. }  
  50.  
  51. }  
  52.  
  53. private Color mProgressTextColor = Color.Black;  
  54.  
  55. public Color ProgressTextColor  
  56.  
  57. {  
  58.  
  59. get 
  60.  
  61. {  
  62.  
  63. return mProgressTextColor;  
  64.  
  65. }  
  66.  
  67. set 
  68.  
  69. {  
  70.  
  71. mProgressTextColor = value;  
  72.  
  73. }  
  74.  
  75. }  
  76.  //C# listview進度條顯示
  77. public int ProgressColumIndex  
  78.  
  79. {  
  80.  
  81. set 
  82.  
  83. {  
  84.  
  85. progressIndex = value;  
  86.  
  87. }  
  88.  
  89. get 
  90.  
  91. {  
  92.  
  93. return progressIndex;  
  94.  
  95. }  
  96.  
  97. }  
  98.  
  99. int progressIndex = -1;  
  100.  
  101.  
  102. /// ﹤summary﹥  
  103.  
  104. /// 檢查是否可以轉化為一個浮點數(shù)  
  105.  
  106. /// ﹤/summary﹥  
  107.  
  108. const string numberstring = "0123456789.";  
  109.  
  110. private bool CheckIsFloat(String s)  
  111.  
  112. {  
  113.  //C# listview進度條顯示
  114. foreach (char c in s)  
  115.  
  116. {  
  117.  
  118. if (numberstring.IndexOf(c) ﹥ -1)  
  119.  
  120. {  
  121.  
  122. continue;  
  123.  
  124. }  
  125.  
  126. else 
  127.  
  128. return false;  
  129.  
  130. }  
  131.  
  132. return true;  
  133.  
  134. }  
  135.  
  136.  
  137. protected override void Dispose(bool disposing)  
  138.  
  139. {  
  140.  
  141. base.Dispose(disposing);  
  142.  
  143. }  
  144.  
  145.  //C# listview進度條顯示
  146. private void InitializeComponent()  
  147.  
  148. {  
  149.  
  150. this.OwnerDraw = true;  
  151.  
  152. this.View = View.Details;  
  153.  
  154. }  
  155.  
  156.  
  157. protected override void OnDrawColumnHeader(  
  158. DrawListViewColumnHeaderEventArgs e)  
  159.  
  160. {  
  161.  
  162. e.DrawDefault = true;  
  163.  
  164. base.OnDrawColumnHeader(e);  
  165.  
  166. }  
  167.  
  168.  
  169. protected override void OnDrawSubItem(  
  170. DrawListViewSubItemEventArgs e)  
  171.  
  172. {  
  173.  
  174. if (e.ColumnIndex != this.progressIndex)  
  175.  
  176. {  
  177.  //C# listview進度條顯示
  178. e.DrawDefault = true;  
  179.  
  180. base.OnDrawSubItem(e);  
  181.  
  182. }  
  183.  
  184. else 
  185.  
  186. {  
  187.  
  188. if (CheckIsFloat(e.Item.SubItems[e.ColumnIndex].Text))  
  189. //判斷當前subitem文本是否可以轉為浮點數(shù)  
  190.  
  191. {  
  192.  
  193. float per = float.Parse(e.Item.  
  194. SubItems[e.ColumnIndex].Text);  
  195.  
  196. if (per ﹥= 1.0f)  
  197.  
  198. {  
  199.  
  200. per = per / 100.0f;  
  201.  
  202. }  
  203.  
  204. Rectangle rect = new Rectangle(e.Bounds.X,  
  205.  e.Bounds.Y, e.Bounds.Width, e.Bounds.Height);  
  206.  
  207. DrawProgress(rect, per, e.Graphics);  
  208.  
  209. }     
  210.  
  211. }  
  212.  
  213. }  
  214.  //C# listview進度條顯示
  215.  
  216. ///繪制進度條列的subitem  
  217.  
  218. private void DrawProgress(Rectangle rect,   
  219. float percent, Graphics g)  
  220.  
  221. {  
  222.  
  223. if (rect.Height ﹥ 2 && rect.Width ﹥ 2)  
  224.  
  225. {  
  226.  
  227. //if ((rect.Top ﹥ 0 && rect.Top ﹤ this.Height)  
  228.  &&(rect.Left ﹥ this.Left && rect.Left ﹤ this.Width))  
  229.  
  230. {  
  231.  
  232. //繪制進度  
  233.  
  234. int width = (int)(rect.Width * percent);  
  235.  
  236. Rectangle newRect = new Rectangle(rect.Left + 1,   
  237. rect.Top + 1, width - 2, rect.Height - 2);  
  238.  
  239. using (Brush tmpb =   
  240. new SolidBrush(this.mProgressColor))  
  241.  
  242. {  
  243.  
  244. g.FillRectangle(tmpb, newRect);  
  245.  
  246. }  
  247.  
  248.  
  249. newRect = new Rectangle(rect.Left +  
  250.  1, rect.Top + 1, rect.Width - 2,  
  251.  rect.Height - 2);  
  252.  
  253. g.DrawRectangle(Pens.RoyalBlue, newRect);  
  254.  
  255. StringFormat sf = new StringFormat();  
  256.  
  257. sf.Alignment = StringAlignment.Center;  
  258.  
  259. sf.LineAlignment = StringAlignment.Center;  
  260.  
  261. sf.Trimming = StringTrimming.EllipsisCharacter;  
  262.  
  263. newRect = new Rectangle(rect.Left + 1,   
  264. rect.Top + 1, rect.Width - 2,   
  265. rect.Height - 2);  
  266.  
  267. using (Brush b =   
  268. new SolidBrush(mProgressTextColor))  
  269.  
  270. {  
  271.  
  272. g.DrawString(  
  273. percent.ToString("p1"), this.Font, b, newRect, sf);  
  274.  
  275. }  
  276.  
  277. }  
  278.  
  279. }  
  280.  //C# listview進度條顯示
  281. else 
  282.  
  283. {  
  284.  
  285. return;  
  286.  
  287. }  
  288.  
  289. }  
  290.  
  291. }  
  292.  

C# listview進度條顯示的基本情況就向你介紹到這里,希望對你了解和學習C# listview進度條顯示有所幫助。

【編輯推薦】

  1. C# WinForm進度條實現(xiàn)淺析
  2. C#多線程控制進度條之長任務操作
  3. C#多線程控制進度條之長異步操作
  4. C#多線程控制進度條之異步調用
  5. C#多線程控制進度條之多線程安全
責任編輯:仲衡 來源: CSDN博客
相關推薦

2009-08-17 15:48:47

C# WinForm進

2009-08-17 15:05:41

C#進度條

2009-08-17 14:36:15

C#進度條實現(xiàn)

2009-08-17 13:56:29

C#進度條的使用

2009-08-17 14:08:33

C#進度條使用

2009-08-17 14:41:47

C#進度條實現(xiàn)

2009-08-27 14:01:41

C#進度條

2009-08-17 17:15:48

C# 進度條效果

2009-08-17 16:29:56

C#多線程控制

2009-08-17 16:41:03

C#多線程控制

2015-07-31 11:19:43

數(shù)字進度條源碼

2011-02-22 14:53:41

titlebar標題欄Android

2009-08-17 16:56:51

C#多線程控制進度條

2009-08-17 16:49:46

C#多線程控制

2009-08-11 14:12:27

C# ListView

2011-07-05 15:16:00

QT 進度條

2024-08-06 14:29:37

2009-06-06 18:54:02

JSP編程進度條

2023-12-11 17:15:05

應用開發(fā)波紋進度條ArkUI

2012-01-17 13:58:17

JavaSwing
點贊
收藏

51CTO技術棧公眾號