2

所以,

我在 tabcontrol 页面上有一个文本框,当有人跳出文本框时,它应该移动到下一个选项卡。在我将表单从 UserControl 切换到实际表单之前,这非常有效。此更改并未更改实际代码。

所以现在,我已经尝试了一切。我将文本框设置为 AcceptTab = True,并且我有 KeyPreview = False(因为如果表单在文本框之前抓取事件,我假设它会搞砸)。

这是我的文本框代码:

 Private Sub txtMsgDTG_KeyDown(ByVal sender As Object, ByVal e As KeyEventArgs) Handles txtMsgDTG.KeyDown

    'check for tabbed out
    If e.KeyCode = Keys.Tab Then
        'If the user tabs into this field after filling out the necessary fields ...
        If txtMsgDTG.Text = String.Empty Then
            'If the user left the field BLANK ...

            'Move to next page:
            TabControl1.TabPages(0).Enabled = True
            TabControl1.TabPages(1).Enabled = True
            TabControl1.TabPages(2).Enabled = False
            TabControl1.TabPages(3).Enabled = False
            TabControl1.TabPages(4).Enabled = False
            TabControl1.SelectedIndex = 1

        Else
            'If the user did NOT leave the field blank ...

            'validate message DTG
            Dim dtgCheck As String
            dtgCheck = ValidateDTG(txtMsgDTG.Text)
            If dtgCheck <> "valid" Then
                MsgBox(dtgCheck)
            Else
                'Move to next page:
                TabControl1.TabPages(0).Enabled = True
                TabControl1.TabPages(1).Enabled = True
                TabControl1.TabPages(2).Enabled = False
                TabControl1.TabPages(3).Enabled = False
                TabControl1.TabPages(4).Enabled = False
                TabControl1.SelectedIndex = 1

            End If

        End If

    End If


End Sub

有什么想法吗?

4

1 回答 1

2

快速修复:

txtMsgDTG.Multiline = True

您可以保留的另一个修复Multiline = False是订阅 TextBox 的PreviewKeyDown事件:

Private Sub txtMsgDTG_PreviewKeyDown(ByVal sender As Object, ByVal e As PreviewKeyDownEventArgs) Handles txtMsgDTG.PreviewKeyDown
  If e.KeyCode = Keys.Tab Then
    e.IsInputKey = True
  End If
End Sub
于 2012-04-19T15:12:08.900 回答