简体   繁体   English

控件不专注于Keyup事件

[英]Control is not getting focused on Keyup event

Hi all I have created a dynamic combo box with a Textbox and a button to appear as dropdown style, every thing works fine but I handled keyup event for the textbox so that when user enter some text I will search for the results and display them 大家好,我创建了一个带有文本框和一个按钮的下拉菜单的动态组合框,一切正常,但是我处理了文本框的keyup事件,因此当用户输入一些文本时,我将搜索结果并显示它们

 private void textBox1_KeyUp(object sender, KeyEventArgs e)
 {
     //Some code to filter my data 
     textBox1.Focus();
 }

But I am unable to set the focus Immediately back to the textbox after results getting displayed so can some one help me 但是我无法在显示结果后立即将焦点设置回文本框,所以有人可以帮助我

Code I used is from here 我使用的代码是从这里

http://www.planetsourcecode.com/vb/scripts/showcode.asp?txtCodeId=8554&lngWid=10 http://www.planetsourcecode.com/vb/scripts/showcode.asp?txtCodeId=8554&lngWid=10

I have found that the Focus() method is a bit flaky. 我发现Focus()方法有点不稳定。

Other options: 其他选项:

textBox1.Select(textBox1.Text.Length - button1, 1);

...or simply: ...或简单地说:

textBox1.Select();

If you can verify that something else is going wrong, then this might be off base, otherwise you might simply be fighting weirdness. 如果您可以验证是否有其他问题出在哪里,那么这可能是错误的,否则您可能只是在与怪异作斗争。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM