這篇文章主要講解了“C# listview進(jìn)度條如何顯示”,文中的講解內(nèi)容簡單清晰,易于學(xué)習(xí)與理解,下面請大家跟著小編的思路慢慢深入,一起來研究和學(xué)習(xí)“C# listview進(jìn)度條如何顯示”吧!

成都創(chuàng)新互聯(lián)專業(yè)為企業(yè)提供海港網(wǎng)站建設(shè)、海港做網(wǎng)站、海港網(wǎng)站設(shè)計、海港網(wǎng)站制作等企業(yè)網(wǎng)站建設(shè)、網(wǎng)頁設(shè)計與制作、海港企業(yè)網(wǎng)站模板建站服務(wù),10多年海港做網(wǎng)站經(jīng)驗,不只是建網(wǎng)站,更提供有價值的思路和整體網(wǎng)絡(luò)服務(wù)。
看看具體的實現(xiàn)過程。
程序比較簡單,就是重載了listview的實現(xiàn),不過很實用!
using System; using System.Collections.Generic; using System.Text; using System.Windows.Forms; using System.Drawing; //C# listview進(jìn)度條顯示namespace WindowsApplication1 { class ListViewEx:System.Windows.Forms.ListView { public ListViewEx() { InitializeComponent(); } //C# listview進(jìn)度條顯示private Color mProgressColor = Color.Red; public Color ProgressColor { get { return this.mProgressColor; } set { this.mProgressColor = value; } } private Color mProgressTextColor = Color.Black; public Color ProgressTextColor { get { return mProgressTextColor; } set { mProgressTextColor = value; } } //C# listview進(jìn)度條顯示public int ProgressColumIndex { set { progressIndex = value; } get { return progressIndex; } } int progressIndex = -1; /// ﹤summary﹥ /// 檢查是否可以轉(zhuǎn)化為一個浮點數(shù) /// ﹤/summary﹥ const string numberstring = "0123456789."; private bool CheckIsFloat(String s) { //C# listview進(jìn)度條顯示foreach (char c in s) { if (numberstring.IndexOf(c) ﹥ -1) { continue; } else return false; } return true; } protected override void Dispose(bool disposing) { base.Dispose(disposing); } //C# listview進(jìn)度條顯示private void InitializeComponent() { this.OwnerDraw = true; this.View = View.Details; } protected override void OnDrawColumnHeader( DrawListViewColumnHeaderEventArgs e) { e.DrawDefault = true; base.OnDrawColumnHeader(e); } protected override void OnDrawSubItem( DrawListViewSubItemEventArgs e) { if (e.ColumnIndex != this.progressIndex) { //C# listview進(jìn)度條顯示e.DrawDefault = true; base.OnDrawSubItem(e); } else { if (CheckIsFloat(e.Item.SubItems[e.ColumnIndex].Text)) //判斷當(dāng)前subitem文本是否可以轉(zhuǎn)為浮點數(shù) { float per = float.Parse(e.Item. SubItems[e.ColumnIndex].Text); if (per ﹥= 1.0f) { per = per / 100.0f; } Rectangle rect = new Rectangle(e.Bounds.X, e.Bounds.Y, e.Bounds.Width, e.Bounds.Height); DrawProgress(rect, per, e.Graphics); } } } //C# listview進(jìn)度條顯示 ///繪制進(jìn)度條列的subitem private void DrawProgress(Rectangle rect, float percent, Graphics g) { if (rect.Height ﹥ 2 && rect.Width ﹥ 2) { //if ((rect.Top ﹥ 0 && rect.Top ﹤ this.Height) &&(rect.Left ﹥ this.Left && rect.Left ﹤ this.Width)) { //繪制進(jìn)度 int width = (int)(rect.Width * percent); Rectangle newRect = new Rectangle(rect.Left + 1, rect.Top + 1, width - 2, rect.Height - 2); using (Brush tmpb = new SolidBrush(this.mProgressColor)) { g.FillRectangle(tmpb, newRect); } newRect = new Rectangle(rect.Left + 1, rect.Top + 1, rect.Width - 2, rect.Height - 2); g.DrawRectangle(Pens.RoyalBlue, newRect); StringFormat sf = new StringFormat(); sf.Alignment = StringAlignment.Center; sf.LineAlignment = StringAlignment.Center; sf.Trimming = StringTrimming.EllipsisCharacter; newRect = new Rectangle(rect.Left + 1, rect.Top + 1, rect.Width - 2, rect.Height - 2); using (Brush b = new SolidBrush(mProgressTextColor)) { g.DrawString( percent.ToString("p1"), this.Font, b, newRect, sf); } } } //C# listview進(jìn)度條顯示else { return; } } } }感謝各位的閱讀,以上就是“C# listview進(jìn)度條如何顯示”的內(nèi)容了,經(jīng)過本文的學(xué)習(xí)后,相信大家對C# listview進(jìn)度條如何顯示這一問題有了更深刻的體會,具體使用情況還需要大家實踐驗證。這里是創(chuàng)新互聯(lián),小編將為大家推送更多相關(guān)知識點的文章,歡迎關(guān)注!
網(wǎng)站欄目:C#listview進(jìn)度條如何顯示
網(wǎng)頁URL:http://www.chinadenli.net/article48/pecpep.html
成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供品牌網(wǎng)站設(shè)計、做網(wǎng)站、全網(wǎng)營銷推廣、企業(yè)建站、面包屑導(dǎo)航、網(wǎng)站建設(shè)
聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請盡快告知,我們將會在第一時間刪除。文章觀點不代表本網(wǎng)站立場,如需處理請聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時需注明來源: 創(chuàng)新互聯(lián)