在文本框中按Tab键时如何触发事件? [英] How to fire an event when the tab key is pressed in a textbox?

查看:1669
本文介绍了在文本框中按Tab键时如何触发事件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

对于当前我正在使用的应用程序,我想使用我自己的自定义控件来模拟组合框,因为我希望它是多列并具有一些附加功能。我正在使用文本框和datagridview来执行此操作。

For the current application I am working on I want to simulate a combo box using my own custom control as I want it to be multi column and have some additional functionality. I am using a text box and a datagridview to do this.

我想复制可以与常规组合框一起使用的建议/追加。我有这个工作很棒。用户可以开始键入,获取建议列表,并可以使用向上和向下键滚动条目。

I want to replicate the suggest/append that can be used with a regular combo box. I've got this working great. The user can begin to type, gets a list of suggestions and can use the up and down keys to scroll through entries.

我已经收到了输入密钥以将所选行作为值。这样做完美,但是我也想捕捉标签键并执行相同操作,就像已经嵌入到组合框控件中的功能一样。

I have already trapped the enter key to take the selected row as the value. This works perfectly but I would also like to trap the tab key and do the same, much like the functionality already embedded in a combo box control.

问题是,显然,vb.net使用Tab键来更改所选的控件,并且在触发子程序之前,我可以调用我的子程序从我的datagridview中选择所选的行。我想要能够取消控件的标签,或者至少找到一种方法来触发我的代码。

The problem is that, obviously vb.net uses the tab key to change the selected control and this fires before I can call my subroutine to take the selected row from my datagridview. I want to be able to cancel tabbing out of the control, or at least find a way to fire my code before it does.

提前感谢。

推荐答案

TextBox还有一个 AcceptsTab 属性,当 Multiline = True

The TextBox also has an AcceptsTab property that works when Multiline = True.

有了这些条件,您现在可以看到是否按Tab键:

With those conditions, you can now see if the tab key was pressed:

Private Sub TextBox1_KeyDown(sender As Object, e As KeyEventArgs) _
                             Handles TextBox1.KeyDown
  If e.KeyCode = Keys.Tab Then
    e.SuppressKeyPress = True
    'do something
  End If
End Sub

这篇关于在文本框中按Tab键时如何触发事件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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