3 Replies - 1255 Views - Last Post: 17 October 2010 - 06:09 AM Rate Topic: -----

#1 xzenon  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 15
  • Joined: 25-September 10

timer and progress bar problem

Posted 17 October 2010 - 04:01 AM

Hi
Im trying to make a progress bar trigger an message when it reach maximum. But my problem is that the massage start spaming up instead of showing just once. I wrote 2 codes but i got almost the same problem can any one take a look at my codes and se what im doing wrong?

first code
private void timer1_Tick(object sender, EventArgs e)

  {

   

   timer1.Interval = 500;

   

   timer1.Tick += new EventHandler(IncreaseProgressBar);

   

   timer1.Start();

   
  }



  private void IncreaseProgressBar(object sender, EventArgs e)

  {

   
   progressBar1.Increment(1);



   if (progressBar1.Value == progressBar1.Maximum)

    
    messagebox.show("hi");
    timer1.Stop();

   

  }




second code
private void timer1_Tick(object sender, EventArgs e)
        {
            
            progressBar1.Minimum = 0;
            progressBar1.Maximum = 100;
            progressBar1.Step = 3;
            progressBar1.PerformStep();
            progressBar1_maximum();
            
        }

        private void progressBar1_maximum()
        {
            {
                if (progressBar1.Value == 100)

                    MessageBox.Show("hi");
                timer1.Stop();
            }
        }



Is This A Good Question/Topic? 0
  • +

Replies To: timer and progress bar problem

#2 CodingSup3rnatur@l-360  Icon User is offline

  • D.I.C Addict
  • member icon

Reputation: 991
  • View blog
  • Posts: 971
  • Joined: 30-September 10

Re: timer and progress bar problem

Posted 17 October 2010 - 04:30 AM

Hello there,

You could try unregistering the tick event in addition to stopping the timer. You could do this as follows:


timer1.Tick -= new EventHandler(IncreaseProgressBar);


Actually, looking at your if statements in both of your code snippets, I think your need to put curly braces to surround the lines after the if condition:

if (progressBar1.Value == progressBar1.Maximum){

    timer1.Stop();
    timer1.Tick -= new EventHandler(IncreaseProgressBar);
    messagebox.show("hi");
 
}




Otherwise, your message may show up repeatedly as it isn't part of the if statement and so runs every time IncreaseProgressBar() is called.

This post has been edited by CodingSup3rnatur@l-360: 17 October 2010 - 04:42 AM

Was This Post Helpful? 2
  • +
  • -

#3 xzenon  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 15
  • Joined: 25-September 10

Re: timer and progress bar problem

Posted 17 October 2010 - 05:56 AM

View PostCodingSup3rnatur@l-360, on 17 October 2010 - 03:30 AM, said:

Hello there,

You could try unregistering the tick event in addition to stopping the timer. You could do this as follows:


timer1.Tick -= new EventHandler(IncreaseProgressBar);


Actually, looking at your if statements in both of your code snippets, I think your need to put curly braces to surround the lines after the if condition:

if (progressBar1.Value == progressBar1.Maximum){

    timer1.Stop();
    timer1.Tick -= new EventHandler(IncreaseProgressBar);
    messagebox.show("hi");
 
}




Otherwise, your message may show up repeatedly as it isn't part of the if statement and so runs every time IncreaseProgressBar() is called.



Tnx that helped
Was This Post Helpful? 0
  • +
  • -

#4 CodingSup3rnatur@l-360  Icon User is offline

  • D.I.C Addict
  • member icon

Reputation: 991
  • View blog
  • Posts: 971
  • Joined: 30-September 10

Re: timer and progress bar problem

Posted 17 October 2010 - 06:09 AM

View Postxzenon, on 17 October 2010 - 04:56 AM, said:

View PostCodingSup3rnatur@l-360, on 17 October 2010 - 03:30 AM, said:

Hello there,

You could try unregistering the tick event in addition to stopping the timer. You could do this as follows:


timer1.Tick -= new EventHandler(IncreaseProgressBar);


Actually, looking at your if statements in both of your code snippets, I think your need to put curly braces to surround the lines after the if condition:

if (progressBar1.Value == progressBar1.Maximum){

    timer1.Stop();
    timer1.Tick -= new EventHandler(IncreaseProgressBar);
    messagebox.show("hi");
 
}




Otherwise, your message may show up repeatedly as it isn't part of the if statement and so runs every time IncreaseProgressBar() is called.



Tnx that helped


No problem.

Could you press the green button next to my post to give me some rep then please :)? Thanks a lot.

This post has been edited by CodingSup3rnatur@l-360: 17 October 2010 - 06:12 AM

Was This Post Helpful? 2
  • +
  • -

Page 1 of 1