我需要一种有效的方法来处理 C# 文本框中的退格键
我有一个 GUI,它有一个文本框,用于显示连接到串行端口的设备的输出。有时该设备会输出“股票行情”。这是一个字符-退格-字符序列,导致模拟时钟的指针使用字符“|”、“/”、“-”和“\”以及空格和退格来转动,以便这些字符覆盖每个字符其他。无论如何,这在文本框中处理得不好,因为它不像终端那样处理退格键。 因此,我花了几乎一整天的时间试图弄清楚如何解决这个问题,但没有成功。 是的,我知道我能做到……
textBox_CONSOLE.Text = textBox_CONSOLE.Text.Substring(0,textBox_CONSOLE.Text.Length-1));
但那效率极低;因此我想要一个更好的方法(如果可能的话)。 想法?
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?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
您可以通过分配 SelectedText 属性来提高效率。首先使用 Select(int, int) 方法选择最后一个字符。
You make it efficient by assigning the SelectedText property. Use the Select(int, int) method first to select the last character.
您是否尝试过 System.Windows.Forms.SendKeys?
Have you tried System.Windows.Forms.SendKeys?