我遇到了这种情况的问题(见标题)。我在一个大面板中有 6 个子面板。我制作了一个继承自主文本框的 TextBox 类。我正在尝试使用 KeyPressed 事件处理程序来处理 Enter 键。当用户按下 Enter 键时,它会从子面板内的一个 TextBox 移动到下一个子面板。到目前为止,我已经让 Enter Key Event 处理程序为焦点所在的面板工作,而无需跳转到下一个面板。
下面是我用来控制动作的子程序。问题是我无法从一个子面板跳到另一个子面板。任何帮助,将不胜感激!
Protected Shared Sub NextControl(ByVal tControl As Control, ByVal Direction As Boolean)
Dim pControl As Control = tControl.TopLevelControl
tControl = pControl.GetNextControl(tControl, Direction)
If Direction = False Then
Dim tParent As Control
While TypeOf tControl Is UserControl
tParent = tControl.Parent
tControl = pControl.GetNextControl(tControl, Direction)
If tControl.Parent Is tParent Then
Exit While
End If
End While
End If
If tBox_P00.ControlNesting > 0 Then
'Dim i As Integer
pControl = tControl.Parent
For i As Integer = 0 To tBox_P00.ControlNesting - 2
pControl = pControl.Parent
Next
End If
If Not tControl Is Nothing Then
Do Until (tControl.TabStop = True) AndAlso (tControl.Enabled = True) AndAlso (tControl.Visible = True) AndAlso (TypeOf tControl Is Tbx00)
tControl = pControl.GetNextControl(tControl, Direction)
'Last in the Panel
If tControl Is Nothing Then
tBox_P00.Select(0, tBox_P00.TextLength)
Beep()
Exit Sub
End If
Loop
tControl.Focus()
Else
tBox_P00.Select(0, tBox_P00.TextLength)
Beep()
End If
Exit Sub
End Sub