萬盛學電腦網

 萬盛學電腦網 >> 網絡編程 >> asp.net編程 >> 仿vs實現WPF好看的進度條

仿vs實現WPF好看的進度條

   為了界面友好,一般的操作時間較長時,都需要增加進度條提示。由於WPF自帶的進度條其實不怎麼好看,而且沒啥視覺效果。後來,裝VS2012時,發現安裝過程中進度條效果不錯,於是上網查了資料。學習了ModernUI(開源的),地址:https://github.com/firstfloorsoftware/mui。

  後來,做了嘗試寫了個Demo,效果不錯。另外,專門錄制了tif文件,方便大家看到效果。廢話不多說,先展示效果:

  一、效果展示

  A、VS2012安裝界面圖;

  B、個人嘗試Demo效果圖:

  二、實現說明

  1、下載MUI相關代碼或者dll文件;

  2、工程中引入該dll,並引入其資源文件;

  復制代碼 代碼如下:

  

  

  

  

  

  

  

  

  3、在需要顯示進度條的頁面,加入控件(其實還是WPF控件,只是MUI擴展了其樣式而已);

  復制代碼 代碼如下:

  

  

  4、後台實現,由於要根據情況更新進度文字及進度條的值。所以,這裡用到了異步BackgroundWorker(具體可以網上查查相關資料);

  ?

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.ComponentModel;   namespace Monitor.Class { /// <summary> /// 異步操作 /// </summary> public class CWorker { /// <summary> /// 對象 /// </summary> private BackgroundWorker backgroundWorker;   /// <summary> /// 後台執行的操作 /// </summary> public Action BackgroundWork { get; set; }   /// <summary> /// 後台任務執行完畢後事件 /// </summary> public event EventHandler<BackgroundWorkerEventArgs> BackgroundWorkerCompleted;   private BackgroundWorkerEventArgs _eventArgs;//異常參數   /// <summary> /// 構造 /// </summary> public CWorker() { _eventArgs = new BackgroundWorkerEventArgs(); backgroundWorker = new BackgroundWorker(); backgroundWorker.WorkerReportsProgress = true; backgroundWorker.WorkerSupportsCancellation = true; backgroundWorker.DoWork += new DoWorkEventHandler(backgroundWorker1_DoWork); backgroundWorker.RunWorkerCompleted += new RunWorkerCompletedEventHandler(backgroundWorker1_RunWorkerCompleted); }   /// <summary> /// 開始工作 /// </summary> public void BegionWork() { if (backgroundWorker.IsBusy) return; backgroundWorker.RunWorkerAsync(); }   /// <summary> /// 工作 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void backgroundWorker1_DoWork(object sender, DoWorkEventArgs e) { if (BackgroundWork != null) { try { BackgroundWork(); } catch (Exception ex) { _eventArgs.BackGroundException = ex; } } }   /// <summary> /// 完成 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void backgroundWorker1_RunWorkerCompleted(object sender, RunWorkerCompletedEventArgs e) { if (this.BackgroundWorkerCompleted != null) { this.BackgroundWorkerCompleted(null, _eventArgs); } } }   /// <summary> /// 事件 /// </summary> public class BackgroundWorkerEventArgs : EventArgs { /// <summary> /// 後台程序運行時拋出的異常 /// </summary> public Exception BackGroundException { get; set; } } }

  ?

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34
copyright © 萬盛學電腦網 all rights reserved