2016-08-15 1 views
0

나는 memotest를 만들고있어 두 개의 다른 이미지를 눌러야하고 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 개체를 사용해야합니다. _ever_ UI 코드에서 Thread.Sleep을 사용하지 마십시오. – PMF

답변

1

Thread.Sleep을 사용하는 대신 System.Timers 클래스를 사용하십시오. 일정 간격 후에 한 이미지를 숨기고 다른 이미지를 표시하십시오. 다른 도움이 필요하면 말해줘.

+0

public 변수가 아니기 때문에 timer_tick에서 "그림"을 다시 표시 할 수 없습니다. 어떻게해야합니까? 개인 무효 timer3_Tick (개체 발신자, EventArgs e) { counter3--; if (counter3 == 0) { CantClick = 0; picAnterior.Visible = true; picAnterior.Visible = true; Application.DoEvents(); counter3 = 3; timer3.Stop(); } } – sol

관련 문제