如何获得后,每个按键preSS在一个WinForms文本框的当前文本?文本框、按键、如何获得、文本

2023-09-06 18:31:16 作者:太阳落山了

我想以过滤项的ListView 为用户键入文本框和我的列表使用的KeyDown 键preSS 事件,但是当我读 textbox.Text ,它总是返回前的最后一个键preSS的文本。有没有一种方法总是得到任何显示在文本框无pressing进入?

I am trying to filter a list of items in a ListView as the user types into a TextBox and I use KeyDown, and KeyPress events but when I read the textbox.Text, it always returns the text before the last key press. Is there a way to always get whatever is shown in the TextBox without pressing enter?

推荐答案

使用的 TextBox.TextChanged 事件(从控制继承)。

时发生的Text属性值的变化。

Occurs when the Text property value changes.

我的建议是尽量不要与关键事件破解这个(下/ preSS /上) - 还有其他的方法来改变文本框的文字,如通过从右键单击上下文粘贴文本菜单。这不涉及pressing的关键。

My advice is to try not to hack this with the key events (down / press / up) - there are other ways to change a text-box's text, such as by pasting text from the right-click context menu. This doesn't involve pressing a key.