Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/325.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
c#计算点击次数_C#_.net_Winforms - Fatal编程技术网

c#计算点击次数

c#计算点击次数,c#,.net,winforms,C#,.net,Winforms,我有一个计时器,30分钟后我想计算点击次数并在文本框中显示。但是怎么做呢?以下是计时器代码: 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 =

我有一个计时器,30分钟后我想计算点击次数并在文本框中显示。但是怎么做呢?以下是计时器代码:

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");
  }
}

在全局上声明您的clickCounter,并在鼠标单击事件中提高您的计数器+。 如果您做得更具体,您可以使用后台工作程序来跟踪时间。 并使用Application.DoEvents()将剩余内容写入文本框 放置一个按钮、两个标签和一个计时器。使用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());
        }
    }

如果您想重用buttoN1来计算点击次数,而不是启动新的计时器,您可以在要保护的代码周围添加If

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;
    }
}

您的问题的具体情况是…?如果您想跟踪给定按钮、应用程序或操作系统中的单击,请添加。button1\u Click中有一个button1。我想数一数的每一次点击。你是说你是科达·奥拉卡·克拉姆·斯奈兹吗?Genel olarak eksik olduğum konu她的tıklamada bir işlem yapmak。mesela bir int a=0;奥尔逊。1.tıklamada a=1,2。tıklamada a=2 olsun istiyorum。您现在可以查看。代码运行您想要的内容。c/p我的代码和runNice,欢迎光临。iyi口径口径dilerim。kod konusunda profilimde电子邮件地址:daha hizli sonuc alabilirsin birsey yazmak Istedigind Aklda Bulunson:)ok teşekküller Serkan Bey。再问最后一个问题?什么是Application.DoEvents()?它的工作是什么?例如,在过程中,您可能需要在过程中更新UI中的一些字段,在下面的更新命令Application.DoEvents()之后,更新您的UI更改。此代码也可以在没有Application.DoEvents()的情况下工作