2010-07-01 3 views
0

나는 타이머가 있으며 30 분 안에 클릭 수를 계산하여 텍스트 상자에 표시하려고합니다. 하지만 어떻게? 여기에 타이머 코드가 있습니다 :클릭 횟수가 0 회입니다.

decimal sure = 10; 
private void button1_Click(object sender, EventArgs e) 
{ 
    button1.Enabled = true; 
    timer1.Start(); 
} 

private void timer1_Tick(object sender, EventArgs e) 
{ 
    sure--; 
    label3.Text = sure.ToString(); 
    if (sure == 0) 
    { 
    timer1.Stop(); 
    MessageBox.Show("Süre doldu"); 
    } 
} 
+1

클릭 수? – Grzenio

+0

그리고 문제의 세부 사항은 ...? –

+0

특정 버튼이나 앱 또는 OS에서 클릭을 추적하려면 여기에 추가하십시오. –

답변

0

clickCounter를 전역으로 선언하고 마우스 클릭 이벤트에서 카운터 ++를 올리십시오. 더 구체적으로 말하면 배경 작업자를 사용하여 시간을 추적 할 수 있습니다. 및 Application.DoEvents()를 사용하여 textBox에 나머지를 쓰십시오. 단추, 레이블 2 개 및 타이머를 넣으십시오. lblClickCount 및 lblRemainingTime

private int clickCounter = 0; 
    private void button1_Click(object sender, EventArgs e) 
    { 
     clickCounter++; 
     lblClickCount.Text = clickCounter.ToString(); 
    } 

    decimal sure = 10; 
    private void timer1_Tick(object sender, EventArgs e) 
    { 
     sure--; 
     lblRemainingTime.Text = sure.ToString(); 
     Application.DoEvents(); 
     if (sure == 0) 
     { 
      timer1.Stop(); 
      MessageBox.Show("Süre doldu. Toplam tiklama sayisi:" + clickCounter.ToString()); 
     } 
    } 
+0

Serkan bey kod olarak açıklarmısınız? 그녀의 얼굴은 그녀의 얼굴에 찍은 사진입니다. mesela bir int a = 0; olsun. 1. tıklamada a = 1, 2. tıklamada a = 2 olsun istiyorum. – karatekid

+0

원하는 코드를 작성하여 내 게시물을 편집하고 있습니다 –

+0

어디서? 기다려야 하나? 도와 주셔서 고맙습니다 ... – karatekid

0

당신은 클릭 수를 계산하는 Button1을 다시 사용할 수 있지만 코드 주위에 보호하려는 경우 당신이 추가 할 수있는 새로운 타이머를 시작하고 싶었다면에 라벨 이름을 바꿉니다.

bool hasTimerStarted = false; 
int numberOfClicks = 0; 
private void button1_Click(object sender, EventArgs e) 
{ 
    if(!hasTimerStarted) 
    { 
     button1.Enabled = true; 
     timer1.Start(); 
     hasTimerStarted = true; 
    } 
    ++numberOfClicks; 
} 

타이머가 만료되면 카운트를 재설정하고 타이머가 시작되었습니다.

private void timer1_Tick(object sender, EventArgs e) 
{ 

    TimeSpan ts = stopWatch.Elapsed; 

    // Format and display the TimeSpan value. 
    string elapsedTime = String.Format("{0:00}:{1:00}:{2:00}.{3:00}", 
     ts.Hours, ts.Minutes, ts.Seconds, 
     ts.Milliseconds/10); 

    label3.Text = elapsedTime; 
    labelClicks.Text = "User clicked " + clicksNo.toString() + "nt times.."; 

    if (stopWatch.ElapsedMilliseconds >= this.minutes * 60 * 1000) 
    { 
     timer1.Stop(); 
     MessageBox.Show("Time elapsed."); 
     hasTimerStarted = false; 
     numberOfClicks = 0; 
    } 
} 
관련 문제