Winform progress bar with loading style

 

progressBar1.Style = System.Windows.Forms.ProgressBarStyle.Marquee;

BackgroundWorker bgw

bgw.WorkerSupportsCancellation = true;
bgw.DoWork += new DoWorkEventHandler(bgw_DoWork);

protected void bgw_DoWork(object sender, DoWorkEventArgs e)
{
  BackgroundWorker worker = sender as BackgroundWorker;

    while (!worker.CancellationPending)
    {
         if (IsHidden) // auto property
         {
              waitingForm.TopLevel = false; // wait form which only includes progress bar with Marquee style.
              waitingForm.TopMost = false;
         }
         else
         {
              waitingForm.TopLevel = true;
              waitingForm.TopMost = true;
              waitingForm.Focus();
              waitingForm.Refresh();
         }
    }
}
posted @ 2012-11-05 16:23  webglcn  阅读(914)  评论(0编辑  收藏  举报