C# 获取在文本框中键入字符之间的时间间隔(C)#

C# 获取在文本框中键入字符之间的时间间隔(C)#,c#,C#,我有一个表单,它有一个文本框和一个标签,我想得到在文本框中输入的第一个字符的时间。然后,如果用户输入的字符超过十个,则标签中将显示输入的第一个字符与输入的第十个字符之间的时间 有人能帮我吗?我用的是C# 这是代码,但我无法完成它,我有很多东西需要编写,但我不知道如何继续 using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawi

我有一个表单,它有一个文本框和一个标签,我想得到在文本框中输入的第一个字符的时间。然后,如果用户输入的字符超过十个,则标签中将显示输入的第一个字符与输入的第十个字符之间的时间

有人能帮我吗?我用的是C#

这是代码,但我无法完成它,我有很多东西需要编写,但我不知道如何继续

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Threading;

namespace n
{
    public partial class Form1 : Form
    {
        int count=0;
        public Form1()
        {
            InitializeComponent();
        }

        private void textBox1_TextChanged(object sender, EventArgs e)
                {
            DateTime t1 = new DateTime();// the time when entering the first charcter
            DateTime t2 = new DateTime();
            t2 = System.DateTime.Now - t1;
            int index = textBox1.SelectionStart;
            Point p;
            p = textBox1.GetPositionFromCharIndex(index);
            Thread t = new Thread(counttext);
            t.Start();
            label1.Text = "t2";


        }

        private int counttext()
        {
            while (textBox1.Text.Length < 10)
            {
                count++;
                if (count == 10)
                    return count;
            }
        }






    }
}
使用系统;
使用System.Collections.Generic;
使用系统组件模型;
使用系统数据;
使用系统图;
使用System.Linq;
使用系统文本;
使用System.Windows.Forms;
使用系统线程;
名称空间n
{
公共部分类Form1:Form
{
整数计数=0;
公共表格1()
{
初始化组件();
}
私有void textBox1\u TextChanged(对象发送方,事件参数e)
{
DateTime t1=new DateTime();//输入第一个字符的时间
DateTime t2=新的DateTime();
t2=System.DateTime.Now-t1;
int index=textBox1.SelectionStart;
p点;
p=textBox1.GetPositionFromCharIndex(索引);
螺纹t=新螺纹(counttext);
t、 Start();
标签1.Text=“t2”;
}
私有int counttext()
{
while(textBox1.Text.Length<10)
{
计数++;
如果(计数=10)
返回计数;
}
}
}
}

谷歌c#教程。。。。我的建议是从一些基本的控制台程序开始,这样你就知道基本的工作原理,然后进入winforms…

GoogleC#教程。。。。我的建议是从一些基本的控制台程序开始,这样你就知道基本的工作原理,然后进入winforms…

这很简单,你必须跟踪文本框的更改事件并保持计数,当计数为0时启动计时器,停止计时器并显示刻度


请注意,我假设您使用的是windows应用程序,文本更改事件内置于c#,只需双击文本框,时间也是默认控件。

这很简单,您必须跟踪文本框的更改事件并保持计数,当计数为0时启动计时器并停止计时器并显示刻度


请注意,我假设您使用的是windows应用程序,文本更改事件内置于c#,只需双击文本框,时间也是默认控件。

我同意Petoj的观点,您确实需要了解c#和.NET Framework的基础知识。但这里有一些代码可以帮助您:

public partial class Form1 : Form 
{ 
   DateTime TimeTypingBegan { get; set; }

   public Form1() 
   { 
      InitializeComponent(); 
   }

   private void textBox1_TextChanged(object sender, EventArgs e) 
   {
      if (textBox1.Text.Length == 1)
         TimeTypingBegan = DateTime.Now;
      else if (textBox1.Text.Length == 10)
         label1.Text = (DateTime.Now - TimeTypingBegan).ToString();
   } 
}

我同意Petoj的观点,你真的需要复习C#和.NET框架的基础知识。但这里有一些代码可以帮助您:

public partial class Form1 : Form 
{ 
   DateTime TimeTypingBegan { get; set; }

   public Form1() 
   { 
      InitializeComponent(); 
   }

   private void textBox1_TextChanged(object sender, EventArgs e) 
   {
      if (textBox1.Text.Length == 1)
         TimeTypingBegan = DateTime.Now;
      else if (textBox1.Text.Length == 10)
         label1.Text = (DateTime.Now - TimeTypingBegan).ToString();
   } 
}

这是web表单(asp.net)还是System.Windows.Forms表单?对于第一个问题,它实际上是一个javascript问题;语法和句子结构,因为它以前几乎不可读。似乎是win forms,否则毫无意义粘贴的代码:-)这是web表单(asp.net)还是System.Windows.forms表单?对于第一个问题,它实际上是一个javascript问题;语法和句子结构,因为它以前几乎不可读。似乎是赢的形式,否则毫无意义粘贴的代码:-)