views:

60

answers:

3

I have a GUI that has a text box that is used to display the output of a device that is connected to a serial port. There are times when that device will output a "ticker". This is a sequence of character-backspace-character that results in the appearance of an analog clock's hands turning using the characters '|', '/', '-' and '\' along with space and backspace so that those characters overwrite each other. Anyway, this doesn't process well in a textbox because it doesn't deal with the backspace the same way a terminal would. So, I've spent almost a full day trying to figure out how to get around this to no avail. Yes, I know I can do...

textBox_CONSOLE.Text = textBox_CONSOLE.Text.Substring(0,textBox_CONSOLE.Text.Length-1));

but that's extremely inefficient; hence I want a better method (if possible). Thoughts?

+1  A: 

You make it efficient by assigning the SelectedText property. Use the Select(int, int) method first to select the last character.

Hans Passant
A: 

Have you tried System.Windows.Forms.SendKeys?

Forgotten Semicolon
Don't do this. It's very unreliable since it always sends to the active application.
jnylen
A: 
        int len = textBox_CONSOLE.Text.Length;
        if (len == 0)
            return;
        textBox_CONSOLE.Select(len - 1, len);
        textBox_CONSOLE.SelectedText = string.Empty;
Dmitry Karpezo