使用“自动完成”选项调用按键事件

时间:2012-07-30 11:40:28

标签: .net vb.net winforms

我使用KeyPress事件来更改TextBox的焦点。它工作正常,直到我使用AutoComplete选项,在此之后它不起作用。

KeyPress的代码:

If Asc(e.KeyChar) = 13 Then
            txtQuantity.Focus()
            txtQuantity.SelectAll()
            lastTxtBox = "name"
End If

TextBox的代码:

txtProductCode.AutoCompleteMode = AutoCompleteMode.Suggest
txtProductCode.AutoCompleteSource = AutoCompleteSource.CustomSource

我想使用两种建议选项。我尝试将按键更改为keyDown,但它仍然无法正常工作。有没有人有任何想法?

1 个答案:

答案 0 :(得分:0)

改为使用KeyDown事件:

Private Sub TB_KeyDown(sender As Object, e As KeyEventArgs) Handles txtProductCode.KeyDown
    If e.KeyCode = Keys.Enter Then
        txtQuantity.Focus()
        txtQuantity.SelectAll()
    End If
End Sub

它对我来说非常完美(经过测试)。

相关问题