我在做一個記事本,我需要按兩張不同的圖片,並且需要保持3-5秒的可見狀態。我試過Thread.Sleep(5000)
,但它沒有顯示我第二個。我該怎麼辦? 我創建幾秒鐘就能看到圖像的唯一方法就是放置一個MessageBox
但這不是我的想法,我不知道其他方式來做到這一點。如何讓兩張圖片在一定時間後不可見
if (pic != null && pic.Name == fondos[i].Name)
{
if (CantClick == 0)
{
ParejaActual = listRandom[i].pareja;
CantClick = 1;
primerI = i;
picAnterior = pic;
imgAnterior = img;
pic.Visible = false;
}
else if (CantClick == 1)
{
pic.Visible = false;
if (ParejaActual == listRandom[i].pareja)
{
SoundPlayer simpleSound = (new SoundPlayer(Configuracion.RootFolder + "aplau.wav"));
simpleSound.Play();
Ganando++;
label3.Text = Ganando.ToString();
//MessageBox.Show("Si");
//NO SE DESTAPA LA SEGUNDA.
//Thread.Sleep(5000);
CantClick = 0;
img.Visible = false;
imgAnterior.Visible = false;
Application.DoEvents();
}
else
{
(new SoundPlayer(Configuracion.RootFolder + "sad.wav")).Play();
MessageBox.Show("No");
Mal++;
CantClick = 0;
label4.Text = Mal.ToString();
pic.Visible = true;
picAnterior.Visible = true;
}
}
}
謝謝!
您需要在表單上使用System.Windows.Forms.Timer對象。不要在UI代碼中使用Thread.Sleep。 – PMF