I\'m creating a WinForm application that takes a person\'s photo with a webcam and am trying to now create a countdown effect. I have 4 images that i would like to cycle thr
You should use
counter++;
this.SuspendLayout();
pbCountDown.Image = new Bitmap("c:/vrfid/apppics/" + counter + ".jpg");
this.ResumeLayout();
I tested it and it was working, hope it helps you
The problem is that you are spinning in a busy loop while the timer is running. You should check the timer stop condition in the event handler.
I am also a bit surprised that the code works. If you are using System.Windows.Forms.Timer
, you should not even get into the event handler and so the counter should not be incremented. Also the counter value is not properly checked nor updated. The while loop can be transformed into endless loop.
Found a solution, no timer required. Thanks for the answers.
int counter = 0;
// start the counter to swap the images
while (counter < 4)
{
// holding off picture taking
counter++;
//MessageBox.Show("c:/vrfid/apppics/" + counter + ".jpg");
pbCountDown.Image = new Bitmap("c:/vrfid/apppics/" + counter + ".jpg");
pbCountDown.Refresh();
Thread.Sleep(1000);
}
// reset counter for timer
counter = 0;
The Windows Timer class uses the message queue for notifying the timer has expired. And so you need to have the message loop running in order to get the correct number of timer expires occuring. So you should set the counter variable to be a class field and then you can increment it inside the event handler. Something like this...
// Main Code
_counter = 0;
tmCountDown.Start();
// Event Handler
private void tmCountDown_Tick(object sender, EventArgs e)
{
_counter++;
if (_counter == 4)
tmCountDown.Stop();
else
pbCountDown.Image = new Bitmap("c:/vrfid/apppics/" + _counter + ".jpg");
}
SET "INTERVAL =1000" in timer properties that's mean your timer every 1000 ms is refreshing And Then use an if(second == 10).....