在表单和面板中使用 ENTER 或 RETURN 作为 TAB [英] Use ENTER or RETURN as TAB in form and panels
问题描述
我的表单是多个控件,例如 Textboxes
和 Panels
,以及 Panels
中的 Textboxes
,这会导致问题.我尝试使键 ENTER
和 RETURN
与 TAB
执行相同的操作,因此选择下一个控件,但出于未知原因,如果我从对面板的任何控件,它不会进入面板中的第一个控件,而是跳到下一个不是面板的控件.
My form as multiple controls like Textboxes
and Panels
, and Textboxes
in Panels
, which cause problem. I try to make keys ENTER
and RETURN
do the same as TAB
, so select next control, but for an unknown reason if I i go from any control to a panel, it doesn't enter the first control in the panel, it skips to the next control which isn't a panel.
我的表单 key preview
已经是 True
并且我的标签索引没问题:第一个文本框是 10,第一个面板是 11,第一个文本框是面板 12.现在它跳到 20,下一个文本框不在面板中.
My form key preview
is already True
and my tab index are okay :
First textbox is 10, first panel 11, first textbox of panel 12. For now it skips to 20, next textbox not in a panel.
基于这个问题的代码:Tab Key Functionality Using Enter键入 VB.Net
这是我的代码
Private Sub Values_KeyDown(ByVal sender As Control,
ByVal e As System.Windows.Forms.KeyEventArgs) Handles Me.KeyDown
If e.KeyCode = Keys.Return Or e.KeyCode = Keys.Enter Then
If TypeOf Me.GetNextControl(Me.ActiveControl, True) Is Panel Then
Me.SelectNextControl(CType(Me.ActiveControl, Panel).Controls.Item(0), True, True, False, True)
Else
Me.SelectNextControl(Me.ActiveControl, True, True, False, True)
End If
e.Handled = True
End If
End Sub
谢谢!
推荐答案
通过 Hans 的回答,我设法通过简单地将嵌套参数更改为 true 并摆脱了应该使其与面板一起工作的部分来使其工作,像这样:
With Hans' answer i manage to make it work by simply changing the nested parameter to true and get rid of the part that was suppose to make it work with panels, like this:
Private Sub Values_KeyDown(ByVal sender As Control, ByVal e As System.Windows.Forms.KeyEventArgs) Handles Me.KeyDown
If e.KeyCode = Keys.Return Or e.KeyCode = Keys.Enter Then
Me.SelectNextControl(Me.ActiveControl, True, True, True, True)
e.Handled = True
End If
End Sub
您仍然需要将表单上的 Key Preview 参数设置为 True
You'll still need to put the Key Preview parameter on your form to True
我还在这里找到了替代方法:如何使 TextBox 上的 Enter 充当 TAB 按钮
I also found an alternative here : How to make Enter on a TextBox act as TAB button
Private Sub Values_KeyDown(ByVal sender As Control, ByVal e As System.Windows.Forms.KeyEventArgs) Handles Me.KeyDown
If e.KeyCode = Keys.Return Or e.KeyCode = Keys.Enter Then
SendKeys.Send("{TAB}")
e.Handled = True
End If
End Sub
这篇关于在表单和面板中使用 ENTER 或 RETURN 作为 TAB的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!