我正在創建一個WinForm應用程序,它將一個人的照片與網絡攝像頭結合在一起,並試圖現在創建一個倒計時效果。我有4張圖片,我想循環瀏覽,但這樣做很難完成。每秒更改圖片箱中的圖像C#
我使用秒計時器,但發生的所有事情是應用程序滯後一點,然後顯示最後一個圖像。有人知道我可以做到這一點嗎?
這裏是我的代碼:
int counter = 0;
// start the counter to swap the images
tmCountDown.Start();
while (counter < 4)
{
// holding off picture taking
}
// reset counter for timer
counter = 0;
tmCountDown.Stop();
/// <summary>
/// timer event to switch between the countdown images
/// </summary>
/// <param name="sender"></param>
/// <param name="e"></param>
private void tmCountDown_Tick(object sender, EventArgs e)
{
counter++;
//MessageBox.Show("c:/vrfid/apppics/" + counter + ".jpg");
pbCountDown.Image = new Bitmap("c:/vrfid/apppics/" + counter + ".jpg");
}
我不看你在哪裏設置定時器的時間間隔...請顯示相應的代碼。 –
你也可以調用圖片框的InvokePaint成員來強制它自己重繪 – tom502
希望你增加計數器。任何方式,做form.update或form.Refresh甚至pictureBox.Refresh或更新方法有時做這項工作。 – Zenwalker