Friday, August 9, 2013

Calculate length of text entered in RichTextBox c# winform

Calculate length of text entered in RichTextBox c# winform

I have RichTextBox and I want to calculate the length of text entered in
the KeyDown event. The problem is for characters in capital form I have to
press Shift which is also getting calculated in the length. See the
following code:
private void rtfText_KeyDown(object sender, KeyEventArgs e)
{
if (e.Modifiers != Keys.Shift)
{
var val = (char)e.KeyValue;
string _typed += val;
}
}
For texts like "Win" with capital 'W' the length of _typed is shown as 4
where as it is 3. How to solve this ?

1 comment: