Login | Register   
Twitter
RSS Feed
Download our iPhone app
TODAY'S HEADLINES  |   ARTICLE ARCHIVE  |   FORUMS  |   TIP BANK
Browse DevX
Sign up for e-mail newsletters from DevX


Tip of the Day
Language: VB4,VB5,VB6
Expertise: beginner
Dec 30, 2000

Avoid beeps on forms without a default button

If a form contains one CommandButton control whose Default property is set to True, the Enter key activates the CommandButton. If the form doesn't contain any default CommandButton control, however, pressing the Enter key when the focus is inside a TextBox control (and a few other controls as well) results in an annoying beep.

You can get rid of this beep by setting the form's KeyPreview property to True and adding the following code routine:


Private Sub Form_KeyPress(KeyAscii As Integer)
    ' check the type of the control that is currently active
    If TypeOf ActiveControl Is TextBox Then
        ' discard the Enter key
        If KeyAscii = vbKeyReturn Then KeyAscii = 0
    End If
End Sub
Francesco Balena
 
Comment and Contribute

 

 

 

 

 


(Maximum characters: 1200). You have 1200 characters left.

 

 

Sitemap