Results 1 to 7 of 7

Thread: Can I ignore Tab key for Text Box?

  1. #1

    Thread Starter
    Frenzied Member
    Join Date
    Jul 1999
    Location
    Huntingdon Valley, PA 19006
    Posts
    1,151
    I tried to use Keypress Event to disable the Tab Key. In Keypress Subroutine, I used "KeyAscii = 0" when vbKeyTab occurred. Text box still lost focus. I used same code to ignore Enter key and it worked as expected.

    Advice anybody?

    Thanx.
    Live long & prosper.

    The Dinosaur from prehistoric era prior to computers.

    Eschew obfuscation!
    If a billion people believe a foolish idea, it is still a foolish idea!
    VB.net 2010 Express
    64Bit & 32Bit Windows 7 & Windows XP. I run 4 operating systems on a single PC.

  2. #2
    Guest
    Try switching the forms "KeyPreview" property to true, and then typing some code in the KeyPress event of the form. Sorry, but I can't help you out with the code if you are after it.

  3. #3
    Hyperactive Member
    Join Date
    Mar 2000
    Posts
    461
    Actually... The "KeyPreview" attribute tells the form to "CHECK" all keystrokes before allowing the relevant control to test for it.

    What you want to do is test for the KeyDown even rather than KeyPress.

    I think Tab is a value of 14 by memory but I could be wrong.

  4. #4
    Lively Member
    Join Date
    Jun 2000
    Location
    Belgium
    Posts
    77
    Sorry Gen-X, but Tab is a value of 9
    KWell

  5. #5
    Hyperactive Member
    Join Date
    Mar 2000
    Posts
    461
    Thanks KWell...

    I knew it was in the sub 32 range somewhere.

  6. #6

    Thread Starter
    Frenzied Member
    Join Date
    Jul 1999
    Location
    Huntingdon Valley, PA 19006
    Posts
    1,151

    Did not work

    The following did not work.
    Code:
    Private Sub TxtMessage_KeyDown(KeyCode As Integer, _
                                        Shift As Integer)
    If KeyCode = vbKeyTab Then
        KeyCode = 0
        Junk = MsgBox("Tab Key") 'Dim for Junk is elsewhere
    End If
    End Sub
    I had similar code in KeyPress event subroutine. Neither recognized the Tab Key. Either the vbKeyTab constant is incorrect (I doubt that) or these subroutines do not provide for trapping & ignoring the Tab Key. Both allow for trapping & ignoring the Return Key.

    I tried the above with KeyPreview True & False.

    My application can live without trapping the Tab Key. When Text Box is active, no control with a TabStop is visible, so focus is lost. I can Mouse click to return to Text Box, but it makes the application behave in a "Non-Professional" manner.

    Any thoughts?
    Live long & prosper.

    The Dinosaur from prehistoric era prior to computers.

    Eschew obfuscation!
    If a billion people believe a foolish idea, it is still a foolish idea!
    VB.net 2010 Express
    64Bit & 32Bit Windows 7 & Windows XP. I run 4 operating systems on a single PC.

  7. #7
    Lively Member
    Join Date
    Feb 2000
    Posts
    118

    Try This

    I couldn't figure it out either, but you could put another textbox under the one you are working with(by under I mean same top,left,height and width)and set it active and inactive with the one you are working with, then insert some code like this.
    Private Sub txtHidden_GotFocus()
    txtYouWantToIgnoreTabKey.SetFocus
    End Sub
    Not pretty, but it works.(I tried it)
    Make sure hidden textbox is next in taborder.
    Kokopeli
    VB6 SP3

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width