Search code examples
c#keypressmessageboxbackspace

In the end of typing, I want to check how many time user press key "Backspace"


I want to make program with C# that can to know how many times user using key "backspace". This is the scenario, User will typing in richtextbox, after they finished typing, I want to know from begining until they press enter, how many time they used "backspace". That information will show up in messagebox like "Backspace used 10 time". Please help me


Solution

  • You can use KeyDown event to count the keys pressed, so it'll be something like the code below.

    int count = 0;
    private void richTextBox1_KeyDown(object sender, KeyEventArgs e)
    {
        if (e.KeyCode == Keys.BackSpace)
            count++;
        else if (e.KeyCode == Keys.Enter)
            //Show Message.
    }