您好,登錄后才能下訂單哦!
今天就跟大家聊聊有關C#中怎么實現一個進度條效果,可能很多人都不太了解,為了讓大家更加了解,小編給大家總結了以下內容,希望大家根據這篇文章可以有所收獲。
using System; using System.Collections.Generic; //C#進度條實現實例using System.ComponentModel; using System.Data; using System.Drawing; using System.Text; using System.Windows.Forms; namespace 進度條2 //C#進度條實現實例{ public partial class Form1 : Form { private BackgroundWorker worker = new BackgroundWorker(); int N = 0; public Form1() { InitializeComponent(); worker.WorkerReportsProgress = true; worker.WorkerSupportsCancellation = true; worker.DoWork += new DoWorkEventHandler(DoWork); worker.ProgressChanged += new ProgressChangedEventHandler(ProgessChanged); worker.RunWorkerCompleted += new RunWorkerCompletedEventHandler(CompleteWork); } public void DoWork( object sender, DoWorkEventArgs e) { e.Result = ComputeFibonacci(worker, e); } public void ProgessChanged( object sender, ProgressChangedEventArgs e) { progressBarX1.Value = e.ProgressPercentage; int V =(int)( e.ProgressPercentage / N); progressBarX1.Text = Convert.ToString(V) + "%"; } //C#進度條實現實例public void CompleteWork( object sender, RunWorkerCompletedEventArgs e) { progressBarX1.Text = "處理完畢!"; } private int ComputeFibonacci( object sender, DoWorkEventArgs e) { for (int i = 0; i <= 92800; i++) { if (worker.CancellationPending) { e.Cancel = true; return -1; } else { //C#進度條實現實例 worker.ReportProgress(i); //引發ProgessChanged事件 } } return -1; } private void btnStart_Click( object sender, EventArgs e) { N = 92800 / 100; progressBarX1.Maximum = 92800; worker.RunWorkerAsync(); //開始執行后臺操作 } private void btnPause_Click( object sender, EventArgs e) { worker.CancelAsync(); //請求暫停后臺操作 } } //C#進度條實現實例 }
看完上述內容,你們對C#中怎么實現一個進度條效果有進一步的了解嗎?如果還想了解更多知識或者相關內容,請關注億速云行業資訊頻道,感謝大家的支持。
免責聲明:本站發布的內容(圖片、視頻和文字)以原創、轉載和分享為主,文章觀點不代表本網站立場,如果涉及侵權請聯系站長郵箱:is@yisu.com進行舉報,并提供相關證據,一經查實,將立刻刪除涉嫌侵權內容。