1

I added only one RichTextBox on form having text say like "Hi.. I am CodeProject."

So, what I wants to do is...

focusing on RichTextBox.. user will type the letter same as shown in RichTextBox. If user's typed letter & RichTextBox letter match it will Highlight it's text letter by letter... and if user press wrong key letter it will show some alert message.

I did something like this... but it not working properly.

first of all I saved all letter in Array

    string[] lettersInText;

    private void Form1_Load(object sender, EventArgs e)
    {
        lettersInText = new string[richTextBox1.TextLength];

        for (int i = 0; i < richTextBox1.TextLength; i++)
        {
            AllLetterInTextBox = richTextBox1.Text;
            FirstLetterInTextBox = AllLetterInTextBox[i].ToString();
            lettersInText[i] = FirstLetterInTextBox;
        }
        richTextBox1.Focus();
    }

and then trying to match all that letter which saved in Array with e.KeyCode on KeyDown event of RichTextBox

        string keycode = e.KeyCode.ToString();

        if (keycode == lettersInText[i].ToString())
        {
            _letters = _letters + e.KeyCode.ToString();
            richTextBox1.Select(0, _letters.Length);
            richTextBox1.SelectionColor = Color.Red;
            richTextBox1.Select(richTextBox1.TextLength, 0);
            richTextBox1.SelectionColor = richTextBox1.ForeColor;
        }
        i++;

I can;t say it working fine ... but only problem is e.KeyDown showing only UPPERCASE letter... even I press lowercase.

rene
  • 41,474
  • 78
  • 114
  • 152
Nilesh Dalvi
  • 57
  • 1
  • 3

0 Answers0