1

I'm working on a function in a C# winforms application that will count characters entered into a richtextbox, but needs to ignore the backspace and shift keys.

Here is the code I've got for this part:

private void inputBox_KeyDown(object sender, KeyEventArgs e)
{
    if (e.KeyCode == Keys.Back || e.KeyCode == Keys.LShiftKey || e.KeyCode == Keys.RShiftKey || e.KeyCode == Keys.Shift)
        characterCount += 0;
    else
        characterCount++;
}

Regardless of this being included, it will still count any instance of the Shift Key. Can someone tell me where I'm going wrong? Please let me know if you need anymore information/code!

Update: Solved my own question. Keys.ShiftKey was what I needed. Posted it as an answer too.

4

1 回答 1

1

对于任何看起来的人来说,我自己的笨蛋解决了这个问题。我需要使用 Keys.ShiftKey。显然,当它更早起作用时,我错过了它(因为我有它,但它没有给我结果,或者我错过了它。

于 2015-10-04T04:48:33.040 回答