Getting the time interval between typing characters in a TextBox, in C#

Posted by sama on Stack Overflow See other posts from Stack Overflow or by sama
Published on 2010-03-27T13:33:44Z Indexed on 2010/04/26 9:53 UTC
Read the original article Hit count: 239

Filed under:

I have a form that has a TextBox and a Label and I want to get the time of the first character entered in the textbox. Then if the user enters more than ten charcaters, the time between the first charcter entered and the tenth charcter entered is displayed in the label.

Can any one help me please? I'm using C#

Here is the code but I cannot complete it and I have many things that need to be written but I don't know how to continue.

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






    }
}

© Stack Overflow or respective owner

Related posts about c#