-
Jul 24th, 2009, 03:09 PM
#1
[RESOLVED] CTRL+A - Select All: Beep sound?
Is there a way to get rid of that beep sound when using CTRL+A to select all text in a textbox?
I'm using this code, with the Form's KeyPreview property set to True.
vb Code:
Private Sub Form_KeyDown(KeyCode As Integer, Shift As Integer)
If Shift = vbCtrlMask Then
If KeyCode = vbKeyA Then
Control_SelectAll Me.ActiveControl
End If
End If
End Sub
Public Sub Control_SelectAll(ByRef ControlObject As Control)
On Error Resume Next
With ControlObject
.SetFocus
.SelStart = 0
.SelLength = Len(.Text)
End With
End Sub
-
Jul 24th, 2009, 03:44 PM
#2
Re: CTRL+A - Select All: Beep sound?
Try setting KeyCode and Shift to 0 after calling your routine, as that will indicate that you have dealt with the key press.
-
Jul 24th, 2009, 03:53 PM
#3
Re: CTRL+A - Select All: Beep sound?
You need to handle the KeyPress event as well. It occurs in addition to the KeyDown and KeyUp events but allows you to cancel a key stroke by setting it's KeyAscii argument to 0.
The KeyAscii value of a Ctrl+Letter key is from 1(A) to 26(Z)
Code:
Private Sub Form_KeyPress(KeyAscii As Integer)
If TypeOf Me.ActiveControl Is VB.TextBox Then
Select Case KeyAscii
Case 3, 8, 22, 24 'Allowable control keys in a textbox ctrl-C, ctrl-H (backspace), ctrl-V, ctrl-X
Case Is < 27
KeyAscii = 0
End Select
End If
End Sub
Last edited by brucevde; Jul 24th, 2009 at 03:58 PM.
-
Jul 24th, 2009, 04:26 PM
#4
Re: CTRL+A - Select All: Beep sound?
Originally Posted by si_the_geek
Try setting KeyCode and Shift to 0 after calling your routine, as that will indicate that you have dealt with the key press.
Yeah, I tried that first and didn't work.
Originally Posted by brucevde
You need to handle the KeyPress event as well. It occurs in addition to the KeyDown and KeyUp events but allows you to cancel a key stroke by setting it's KeyAscii argument to 0.
The KeyAscii value of a Ctrl+Letter key is from 1(A) to 26(Z)
Code:
Private Sub Form_KeyPress(KeyAscii As Integer)
If TypeOf Me.ActiveControl Is VB.TextBox Then
Select Case KeyAscii
Case 3, 8, 22, 24 'Allowable control keys in a textbox ctrl-C, ctrl-H (backspace), ctrl-V, ctrl-X
Case Is < 27
KeyAscii = 0
End Select
End If
End Sub
Thanks. I just added the If KeyAscii < 27 part and it fixed it.
-
Jul 24th, 2009, 04:39 PM
#5
Re: [RESOLVED] CTRL+A - Select All: Beep sound?
I just added the If KeyAscii < 27 part and it fixed it.
Just to be sure you understand that without the Case 3,8,22,24 line the user won't be able to delete anything using the Backspace key nor do any Cut/Paste/Copy operations. Those keys will not cause a Beep because they are valid keystrokes in the TextBox.
If that is allright then
-
Jul 24th, 2009, 09:54 PM
#6
Re: [RESOLVED] CTRL+A - Select All: Beep sound?
Originally Posted by brucevde
Just to be sure you understand that without the Case 3,8,22,24 line the user won't be able to delete anything using the Backspace key nor do any Cut/Paste/Copy operations. Those keys will not cause a Beep because they are valid keystrokes in the TextBox.
If that is allright then
Hm, I had no idea about the 3, 22, or 24. Thanks.
Tags for this Thread
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|