2016-08-15 83 views
0

我在做一个记事本,我需要按两张不同的图片,并且需要保持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; 
     } 
    } 
} 

谢谢!

+4

您需要在表单上使用System.Windows.Forms.Timer对象。不要在UI代码中使用Thread.Sleep。 – PMF

回答

1

而不是使用Thread.Sleep,使用System.Timers类。间隔后,只需隐藏一个图像并显示其他图像。告诉我你是否需要其他帮助。

+0

我无法再显示timer_tick中的“pic”,因为它是非公共变量。我能怎么做? private void timer3_Tick(object sender,EventArgs e) { counter3--;如果(counter3 == 0) { CantClick = 0; picAnterior.Visible = true; picAnterior.Visible = true; Application.DoEvents(); counter3 = 3; timer3.Stop(); } } – sol

相关问题