不用代理實現彈出進度條表單

來源:互聯網
上載者:User

彈出進度條的表單名稱:ProcessBar
主表單:Form1
實現的功能:Form1要執行大工作量的操作,需要彈出一個表單顯示進度條

實現方法:

ProcessBar表單:

在ProcessBar表單中設定FormBorderStyle為None ,StartPosition為CenterScreen
在表單中央放一個progressBar1控制項
設定progressBar1控制項的Maximun=20,step=1  
在progressBar1控制項的上面放label控制項(顯示百分比)
將progressBar1控制項和label控制項的聲明訪問類型改為public
 
改完代碼如下:
  public System.Windows.Forms.ProgressBar progressBar1;
  public System.Windows.Forms.Label label1;

Form1表單:

在要觸發大工作量事件的地方這樣寫:
//按鈕:執行大工作量字串串連
    private void button5_Click(object sender, System.EventArgs e)
  {
   ProcessBar pj=new ProcessBar();
   pj.Show();
  //開始處理大量耗時工作
   string sor="";
   for(int i=0;i<20000;i++)
   {
    sor+=i.ToString();
    if(i%1000==0)
    {
     if(pj.progressBar1.Value==20)
      pj.progressBar1.Value=0;
     pj.progressBar1.Value++;
     pj.label1.Text="已完成:"+string.Format("{0:p}",(double)pj.progressBar1.Value/20);
     //pj.label1.Text="已完成:"+pj.progressBar1.Value+"/20";
     Application.DoEvents();
    }
   }
  //工作完成,關閉進度條表單
   pj.Close();
  }

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.