开发者

I need an efficient way to process a backspace in a C# text box

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?


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


        int len = textBox_CONSOLE.Text.Length;
        if (len == 0)
            return;
        textBox_CONSOLE.Select(len - 1, len);
        textBox_CONSOLE.SelectedText = string.Empty;


Have you tried System.Windows.Forms.SendKeys?

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜