none
Carregar ProgressBar RRS feed

  • Question

  • Quando aperto no botão para começar a carregar a ProgressBar, e quando acaba de carregar exibe a mensagem carregado!!!!!

    Como faço..

    ATT Maicon Fermino


    Monday, July 22, 2013 2:23 PM

Answers

  • private void button1_Click(object sender, EventArgs e)

    {

    progressBar1.Maximum = 100;

    backgroundWorker1.WorkerReportsProgress = true;

    backgroundWorker1.ProgressChanged += new ProgressChangedEventHandler(backgroundWorker1_ProgressChanged);

    backgroundWorker1.DoWork += new DoWorkEventHandler(backgroundWorker1_DoWork);

    backgroundWorker1.RunWorkerCompleted += new RunWorkerCompletedEventHandler(backgroundWorker1_RunWorkerCompleted);

    backgroundWorker1.RunWorkerAsync(); 

    }

           

    private void backgroundWorker1_DoWork(object sender, DoWorkEventArgs e)

    {

     for (int i = 0; i < 100; i++)

      {

       Thread.Sleep(30);

       backgroundWorker1.ReportProgress(i); //run in back thread

      }

    }

    private void backgroundWorker1_ProgressChanged(object sender, ProgressChangedEventArgs e)

    {

    progressBar1.Value = e.ProgressPercentage;

    progressBar1.Refresh();

     try

      {

       int percent = (int)(((double)progressBar1.Value / (double)progressBar1.Maximum) * 100);

      progressBar1.CreateGraphics().DrawString(percent.ToString() + "%", new Font("Arial", (float)8.25, FontStyle.Regular), Brushes.Black, new PointF(progressBar1.Width / 2 - 10, progressBar1.Height / 2 - 7));               

      }

      catch

      {

       MessageBox.Show("Processo não terminado!!!");

      }

    }

           

    private void backgroundWorker1_RunWorkerCompleted(object sender, RunWorkerCompletedEventArgs e)

    {

    progressBar1.Value = progressBar1.Maximum;

    MessageBox.Show("Pode entrar!!!");

    }
    Monday, July 22, 2013 6:37 PM

All replies

  • private void button1_Click(object sender, EventArgs e)

    {

    progressBar1.Maximum = 100;

    backgroundWorker1.WorkerReportsProgress = true;

    backgroundWorker1.ProgressChanged += new ProgressChangedEventHandler(backgroundWorker1_ProgressChanged);

    backgroundWorker1.DoWork += new DoWorkEventHandler(backgroundWorker1_DoWork);

    backgroundWorker1.RunWorkerCompleted += new RunWorkerCompletedEventHandler(backgroundWorker1_RunWorkerCompleted);

    backgroundWorker1.RunWorkerAsync(); 

    }

           

    private void backgroundWorker1_DoWork(object sender, DoWorkEventArgs e)

    {

     for (int i = 0; i < 100; i++)

      {

       Thread.Sleep(30);

       backgroundWorker1.ReportProgress(i); //run in back thread

      }

    }

    private void backgroundWorker1_ProgressChanged(object sender, ProgressChangedEventArgs e)

    {

    progressBar1.Value = e.ProgressPercentage;

    progressBar1.Refresh();

     try

      {

       int percent = (int)(((double)progressBar1.Value / (double)progressBar1.Maximum) * 100);

      progressBar1.CreateGraphics().DrawString(percent.ToString() + "%", new Font("Arial", (float)8.25, FontStyle.Regular), Brushes.Black, new PointF(progressBar1.Width / 2 - 10, progressBar1.Height / 2 - 7));               

      }

      catch

      {

       MessageBox.Show("Processo não terminado!!!");

      }

    }

           

    private void backgroundWorker1_RunWorkerCompleted(object sender, RunWorkerCompletedEventArgs e)

    {

    progressBar1.Value = progressBar1.Maximum;

    MessageBox.Show("Pode entrar!!!");

    }
    Monday, July 22, 2013 6:37 PM
  • Hi Maicon,

      Welcome to MSDN Forum Support.

      Thank you for sharing your solution with us. Your efforts will benefit more people.

      Sincerley,

      Jason Wang


    Jason Wang
    MSDN Community Support | Feedback to us
    Develop and promote your apps in Windows Store
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.

    Tuesday, July 23, 2013 4:40 AM