使用组合框的KeyDown事件时的Tab键 [英] Tab key while with the KeyDown event of combobox

查看:120
本文介绍了使用组合框的KeyDown事件时的Tab键的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图检测用户何时在使用KeyDown的同时使用Tab键
组合框的事件.似乎可以使用所有键(Enter,
T,...),但不能使用Tab键(e.KeyCode = Keys.Tab).任何人
遇到过类似的问题?任何解决方案,解决方法?谢谢

私人Sub ComboBox1_KeyDown(ByVal发件人为对象,ByVal e As
System.Windows.Forms.KeyEventArgs)处理ComboBox1.KeyDown


如果e.KeyCode = Keys.Tab然后
Debug.WriteLine("hello")"从此不再打印
如果结束

如果e.KeyCode = Keys.Enter然后
Debug.WriteLine("hello")"按预期的方式打印
如果

解决方案

,则结束,因为该Tab已处理.使用ComboBox的PreviewKeyDown事件,您将按Tab键.我们/library/system.windows.forms.control.onpreviewkeydown.aspx>事件 [在MSDN上 [ End If

If e.KeyCode = Keys.Enter Then
Debug.WriteLine("hello") ''THIS PRINTS AS EXPECTED
End If

解决方案

That''s becuase the Tab is handled. Use the PreviewKeyDown event of the ComboBox and you''ll get the press of Tab


Use the OnPreviewKeyDown event[^] of the combobox.


The tab key is handled by the form itself, not the control. Why should the control care about the tab key? What I think you want to do is handle the LostFocus event. However, if you insist on trapping the tab key here''s how to do it:

On MSDN [^]


这篇关于使用组合框的KeyDown事件时的Tab键的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆