使用AutoCompleteMode的奇怪TextBox行为.附加:Ctrl + A清除文本 [英] Strange TextBox behavior using AutoCompleteMode.Append: Ctrl+A clears the text
问题描述
我在TextBox控件中使用 AutoCompleteMode
设置为 AutoCompleteMode.Append
.
自动完成功能将文本追加到现有文本并将其选中后,如果按 Ctrl + A 选择所有文本,则将清除textBox.
I use AutoCompleteMode
set to AutoCompleteMode.Append
in TextBox control.
After the auto-complete feature appends text to the existing and selects it, if I press Ctrl+A to select all the text, the textBox is cleared.
任何文本框都会发生这种情况,您可以自己进行测试.
你知道如何解决吗?
It happens with any textbox, you can test it by your own.
Do you know how to fix it?
推荐答案
如果使用此快捷方式,那就很烦人了.
这种组合会被拦截,并且在 AutoCompleteMode = AutoCompleteMode.Append
时行为不当.当列表中的部分单词被选中时,您可以看到它;按 ENTER (此处等同于 CTRL + A )将其全部选中,然后按 END 和 BACKSPACE :文本选择实际上并没有清除,最后一个字母被神奇地重新选择,而不是删除.
It can be annoying, if you use this shortcut, that is.
That combination is intercepted along the way and misbehaves when AutoCompleteMode = AutoCompleteMode.Append
. You can see it when a word in the list is partially selected; press ENTER (the CTRL+A equivalent here) to select it all, then press END and BACKSPACE: the text Selection wasn't actually cleared, the last letter is magically re-selected instead of deleted.
作为一种简单的解决方法,您可以在检测到该组合时抑制按键输入,并使用 SelectAll()
自己选择文本:
(如上所述,按 Enter
表示相同的意思)
As a simple workaround, you can suppress the key presses when you detect that combination and use SelectAll()
to select the text yourself:
(as noted, pressing Enter
would to the same thing)
Private Sub TextBox1_KeyDown(sender As Object, e As KeyEventArgs) Handles TextBox1.KeyDown
If e.Control AndAlso e.KeyCode = Keys.A Then
e.SuppressKeyPress = True
TextBox1.SelectAll()
End If
End Sub
这篇关于使用AutoCompleteMode的奇怪TextBox行为.附加:Ctrl + A清除文本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!