|
-
Sep 24th, 2001, 03:12 AM
#1
Thread Starter
Lively Member
disable key
i want to disable some keys on the keyboard
when a user starts entering text into a text box.
will it be posiible
if so how
-
Sep 24th, 2001, 03:17 AM
#2
New Member
different idea
why don't you just do something like this:
just add the keys that you don't want them to press
if text1.text ="1"
then exit sub
-
Sep 24th, 2001, 03:20 AM
#3
Fanatic Member
If you just want to control what they type into a text box, then you can just trap the keys you don't want.
e.g. if you just want numbers and ':', do this:
VB Code:
If InStr("0123456789:", Chr$(KeyAscii)) = 0 And KeyAscii <> 8 Then
Beep
KeyAscii = 0
End If
(KeyAscii 8 is the BackSpace key, which you probably want to allow.)
Note that this will not stop a user from pasting a string, so you may want to check the text box in its LostFocus event.
You might also want to take a look at the masked edit box that comes with VB. It's fully documented in VB.
Last edited by BrianHawley; Sep 24th, 2001 at 03:24 AM.
Brian
(Fighting with the RightToLeft bugs in VS 2005)
-
Sep 24th, 2001, 04:58 AM
#4
Thread Starter
Lively Member
hai
the code works fine but it does not for tab key.
i want to the tabkey does not work for my textbox.
if pressess tab key it should not focus the next text box
-
Sep 24th, 2001, 05:33 AM
#5
Fanatic Member
That's not so easy.
You can't trap the Tab key with KeyDown or KeyPress.
You will have to use the GetKeyState API to see if it has been pressed.
VB Code:
Option Explicit
Private Declare Function GetKeyState Lib "user32" (ByVal nVirtKey As Long) As Integer
Private Sub Text1_Validate(Cancel As Boolean)
Dim RetVal As Integer
RetVal = GetKeyState(vbKeyTab)
If RetVal < 0 Then
Beep
Cancel = True
End If
End Sub
Brian
(Fighting with the RightToLeft bugs in VS 2005)
-
Sep 24th, 2001, 06:15 AM
#6
You can set the TabStop property to False on each control on the form when the TextBox get the focus and turn them back when it lose the focus.
VB Code:
Private Sub Text1_GotFocus()
Dim ctl As Control
On Error Resume Next
For Each ctl In Me.Controls
ctl.TabStop = False
Next
End Sub
Private Sub Text1_LostFocus()
Dim ctl As Control
On Error Resume Next
For Each ctl In Me.Controls
ctl.TabStop = True
Next
End Sub
Best regards
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
|