我正在做备忘录,我需要按两个不同的图像,并且它们需要保持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;
}
}
}
谢谢!
最佳答案
而不是使用Thread.Sleep,而是使用System.Timers类。间隔后,只需隐藏一个图像,然后显示另一个即可。告诉我是否需要其他帮助。
关于c# - 在特定时间后如何使两张图片不可见,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38955646/