Question

I've got a simple winform. In it has a single TextBox control. In that, i've wired up the KeyPress event. Why? I'm trying to capture everything the user types in that textbox. But, when they hit return or enter, i then grab everything they've typed and send it to a command parser to do stuff.

I then display on the screen (in a RichTextBox) whatever they typed, so they know the command is about to get processed.

Simple stuff.

But the problem is when I hit the 'backspace' key. The Gui displays the incorrect text, a weird character that represents the backspace character and then the correct text.

So if i type this... ( == the backspace key)

abcdxxx<BS><BS><BS>efg

the gui displays that.

I want it to display

abcdefg

(notice the XXX chars and the 3 backspace chars and not displayed).

Any suggestions?

Was it helpful?

Solution

On key press event check if the key is backspace don't store it, instead delete the last character.

OTHER TIPS

Try using the TextBox.TextChanged event instead.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top