CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 3 of 3
  1. #1
    Join Date
    Sep 2011
    Posts
    4

    Question Im new, need a little help :O)

    I have made this botton, which make a timer start, and a processbar run. When it is finished, i want the processbar to reset, så i can click the botton again.

    My timer look like this:

    private void button1_Click(object sender, EventArgs e)
    {
    timer1.Enabled = true;


    }

    private void timer1_Tick(object sender, EventArgs e)
    {
    progressBar1.Minimum = 0;
    progressBar1.Maximum = 300;
    progressBar1.Step = 50;
    progressBar1.PerformStep();

    , But what next?

    Thanks for help.

  2. #2
    Join Date
    Jul 2008
    Location
    WV
    Posts
    5,362

    Re: Im new, need a little help :O)

    progressBar1.Value=0;
    Always use [code][/code] tags when posting code.

  3. #3
    Join Date
    May 2011
    Location
    Washington State
    Posts
    220

    Re: Im new, need a little help :O)

    Greetings,

    First, set your progress bar properties (min,max,step) on the control in design view, or set them during your form initialization (load)... no need to set them with each tick of the timer.

    Second, after you step your progress bar with each timer tick, you need to check to see if you have reached the progress bar's maximum value, and if you have, you simply stop your timer and set your progress bar value to zero (or it's min value).

    Something like this...

    Code:
    (on form load)
    {
       progressBar1.Minimum = 0;
       progressBar1.Maximum = 300;
       progressBar1.Step = 50;
    }
    
    private void button1_Click(object sender, EventArgs e)
    {
       timer1.Start();
       button1.Enabled = false;
    }
    
    private void timer1_Tick(object sender, EventArgs e)
    {
       if (progressBar.Value == progressBar.Maximum)
       {
          timer1.Stop();
          progressBar1.Value = 0;
          button1.Enabled = true;
       }
       else
          progressBar1.PerformStep();
    }

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured