新聞中心
這里有您想知道的互聯(lián)網(wǎng)營(yíng)銷解決方案
C#進(jìn)度條實(shí)現(xiàn)實(shí)例
C#進(jìn)度條實(shí)現(xiàn)實(shí)例是如何操作的呢?讓我們看看下面的代碼:

- using System;
- using System.Collections.Generic;
- //C#進(jìn)度條實(shí)現(xiàn)實(shí)例
- using System.ComponentModel;
- using System.Data;
- using System.Drawing;
- using System.Text;
- using System.Windows.Forms;
- namespace 進(jìn)度條2
- //C#進(jìn)度條實(shí)現(xiàn)實(shí)例
- {
- 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#進(jìn)度條實(shí)現(xiàn)實(shí)例
- 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#進(jìn)度條實(shí)現(xiàn)實(shí)例
- worker.ReportProgress(i);
- //引發(fā)ProgessChanged事件
- }
- }
- return -1;
- }
- private void btnStart_Click(
- object sender, EventArgs e)
- {
- N = 92800 / 100;
- progressBarX1.Maximum = 92800;
- worker.RunWorkerAsync();
- //開(kāi)始執(zhí)行后臺(tái)操作
- }
- private void btnPause_Click(
- object sender, EventArgs e)
- {
- worker.CancelAsync();
- //請(qǐng)求暫停后臺(tái)操作
- }
- } //C#進(jìn)度條實(shí)現(xiàn)實(shí)例
- }
C#進(jìn)度條實(shí)現(xiàn)實(shí)例的相關(guān)內(nèi)容就向你介紹到這里,希望對(duì)你了解和學(xué)習(xí)C#進(jìn)度條實(shí)現(xiàn)有所幫助。
【編輯推薦】
- C#調(diào)用Windows API之參數(shù)類型淺析
- C#中調(diào)用Windows API之托管對(duì)象
- C#進(jìn)度條的使用及開(kāi)發(fā)淺析
- C#進(jìn)度條使用之多線程應(yīng)用淺析
- C#進(jìn)度條實(shí)現(xiàn)之異步實(shí)例淺析
新聞標(biāo)題:C#進(jìn)度條實(shí)現(xiàn)實(shí)例
本文鏈接:http://m.fisionsoft.com.cn/article/dpsdoss.html


咨詢
建站咨詢
