在 VB.Net Windows 应用程序中以编程方式触发 Tab 键功能

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/3402385/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-15 14:58:02  来源:igfitidea点击:

Programatically triggering tab key functionality in a VB.Net windows application

windowsdesktop

提问by Ramesh

How can I programatically trigger the tab key functionality in a VB.Net windows application?

如何以编程方式触发 VB.Net Windows 应用程序中的 Tab 键功能?

Currently in my application I am using one splitter when I press the tab key, and the focus is moving in the right order.

目前在我的应用程序中,当我按下 Tab 键时,我使用了一个分隔符,并且焦点以正确的顺序移动。

However I need to use arrow keys to move the focus to next controls, in the same way that the focus is going when the user presses the tab keys.

但是,我需要使用箭头键将焦点移动到下一个控件,就像用户按下 Tab 键时焦点的移动方式一样。

Thanks in Advance

提前致谢

采纳答案by KallDrexx

You can simulate the SendKeys.Send(string)method (in the Systems.Windows.Forms namespace). To simulate a tab keypress you would call SendKeys.Send("{TAB}").

您可以模拟该SendKeys.Send(string)方法(在 Systems.Windows.Forms 命名空间中)。要模拟选项卡按键,您可以调用SendKeys.Send("{TAB}").

To see all the key codes, check out http://msdn.microsoft.com/en-us/library/system.windows.forms.sendkeys.aspx

要查看所有密钥代码,请查看http://msdn.microsoft.com/en-us/library/system.windows.forms.sendkeys.aspx

回答by Koshelew

Better late, than never, since i found this post looking for a solution to a similar problem.

迟到总比没有好,因为我发现这篇文章正在寻找类似问题的解决方案。

Windows Form type has ContainerControl somewhere in its chain of inheritance and that has a method ProcessTabKey(Boolean trueForForward) . It does exactly what you need, inside your form instance this.ProcessTabKey(true) will move focus forward along the tab index and this.ProcessTabKey(false) will move it backward.

Windows 窗体类型在其继承链中的某处有 ContainerControl 并且有一个方法 ProcessTabKey(Boolean trueForward) 。它完全符合您的需要,在您的表单实例中, this.ProcessTabKey(true) 将沿着选项卡索引向前移动焦点,而 this.ProcessTabKey(false) 将向后移动它。

回答by Abdul Sammad

Very simple code

很简单的代码

Write Down this in KeyDown Event of Datagridview

在 Datagridview 的 KeyDown 事件中记下这个

   If e.KeyCode = Keys.Enter Then
        ' Your code here
        SendKeys.Send("{TAB}")
        e.Handled = True
   End If