开发者

Visual Basic 2008 auto-scan controls

开发者_如何学Python

I have a form containes some controls (buttons) how i can make the program autoscan these controls one by one and whenever a button higlited I can bress enter to press this button. Using Visual Basic 2008


You don't have to autoscan the controls, pressing TAB cycles through the controls on the form. Just press TAB until you have the right control selected and then use the KeyDown method for the control:

Private Sub Button1_KeyDown(byVal sender As Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles Button1.KeyDown
    If e.KeyCode = Windows.Forms.Keys.Enter Then
        ' Do whatever
    End If
End Sub

In the If Statement, I recommend you reference a custom Sub that you'll also reference in the Button1_Click event. This will allow you to do make sure that hitting Enter on the selected control and clicking on it do the same thing.

The only downside to this is that you have to write Event Handlers as shown above for every control on your form if that's what you want.

HTH

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜