Change image in picturebox every second C#

后端 未结 5 1532
一整个雨季
一整个雨季 2021-01-13 13:08

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

5条回答
  •  太阳男子
    2021-01-13 13:36

    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");
        }
    

提交回复
热议问题