title: KeyUp and KeyDown events
body: <p>I'm working on a typing program to learn touch typing and increase speed.
  The program generates random words in the textbox (txtsrc) and the user must type the word in another textbox(txtinput) everything is going right until I stuck in this problem: I want to compare every char in txtinput when the user hit the key down if the key is correct to keep going if not change the color of char in txtsrc to red.
  how can I allow the user to use the backspace to remove his errs
  and how to compare the chars while the user input the text
  I can't find the right algorithm please help</p>
  <p>private void txtinput_KeyUp(object sender, KeyEventArgs e)
  {</p>
  <pre><code>        if (keycount &lt; 0) { keycount++; }
          if (e.KeyCode == Keys.Back)
          {
              --keycount;
              txtsrc.Select(keycount, 1);
              txtsrc.SelectionColor = Color.Black;
  
          }
          if (keycount &gt;= 0 &amp;&amp; txtinput.Text.Length &gt; 0)
              if (txtsrc.Text[keycount] != txtinput.Text[txtinput.Text.Length - 1])
              {
                  txtsrc.Select(keycount, 1);
                  txtsrc.SelectionColor = Color.Red;
              }
          if (e.KeyCode != Keys.Back)
          {
              keycount++;
              label1.Text = &quot;Keycount: &quot; + keycount.ToString();
          }
      }
  </code></pre>