日韩无码专区无码一级三级片|91人人爱网站中日韩无码电影|厨房大战丰满熟妇|AV高清无码在线免费观看|另类AV日韩少妇熟女|中文日本大黄一级黄色片|色情在线视频免费|亚洲成人特黄a片|黄片wwwav色图欧美|欧亚乱色一区二区三区

RELATEED CONSULTING
相關(guān)咨詢(xún)
選擇下列產(chǎn)品馬上在線溝通
服務(wù)時(shí)間:8:30-17:00
你可能遇到了下面的問(wèn)題
關(guān)閉右側(cè)工具欄

新聞中心

這里有您想知道的互聯(lián)網(wǎng)營(yíng)銷(xiāo)解決方案
C#listview進(jìn)度條顯示淺析

C# listview進(jìn)度條顯示是如何實(shí)現(xiàn)的呢?讓我們來(lái)看看具體的實(shí)現(xiàn)過(guò)程。

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

 
 
 
  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進(jìn)度條顯示
  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進(jìn)度條顯示
  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進(jìn)度條顯示
  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. /// 檢查是否可以轉(zhuǎn)化為一個(gè)浮點(diǎn)數(shù)  
  105.  
  106. /// ﹤/summary﹥  
  107.  
  108. const string numberstring = "0123456789.";  
  109.  
  110. private bool CheckIsFloat(String s)  
  111.  
  112. {  
  113.  //C# listview進(jìn)度條顯示
  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進(jìn)度條顯示
  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進(jìn)度條顯示
  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. //判斷當(dāng)前subitem文本是否可以轉(zhuǎn)為浮點(diǎn)數(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進(jìn)度條顯示
  215.  
  216. ///繪制進(jìn)度條列的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. //繪制進(jìn)度  
  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進(jìn)度條顯示
  281. else 
  282.  
  283. {  
  284.  
  285. return;  
  286.  
  287. }  
  288.  
  289. }  
  290.  
  291. }  
  292.  

C# listview進(jìn)度條顯示的基本情況就向你介紹到這里,希望對(duì)你了解和學(xué)習(xí)C# listview進(jìn)度條顯示有所幫助。


分享題目:C#listview進(jìn)度條顯示淺析
地址分享:http://www.5511xx.com/article/cdjdeeh.html