Results 1 to 4 of 4

Thread: How do I create a textbox in vb that lets you insert tabs?

  1. #1
    Join Date
    Jan 2009
    Posts
    38

    How do I create a textbox in vb that lets you insert tabs?

    hi

    I want to create a textbox that lets user insert tabs. I dont know why this is not possible to insert tab for me in a textbox & i need to make it possible on my form. Please provide me what code i must use for this?

  2. #2
    Join Date
    May 2008
    Posts
    44

    Re: How do I create a textbox in vb that lets you insert tabs?

    you want to give users the ability to tab between controls AND enter tabs in the Rich Textbox. Fortunately, VB provides the tools for you to do so in the Rich Textbox control's KeyDown() event.



    As you probably know, the Rich Textbox fires this event when a user presses a key while the control has the focus. Like all KeyDown() events, you can use code to determine which key the user pressed and react accordingly. To capture the Tab key and insert a tab space into the Rich Textbox control's edit area, we could use the following:

    Code:
    Private Sub RichTextBox1_KeyDown(KeyCode _
    
         As Integer, Shift As Integer)
    
    Dim mblnTabPressed As Boolean
    
     
    
    mblnTabPressed = (KeyCode = vbKeyTab)
    
    If mblnTabPressed Then
    
        RichTextBox1.SelText = vbTab
    
        KeyCode = 0
    
    End If
    
    End Sub

  3. #3
    Join Date
    May 2008
    Posts
    35

    Re: How do I create a textbox in vb that lets you insert tabs?

    In the example below, the Text2 box will accept and hold TAB keystrokes, keeping them in the Text property along with the other entered characters. The Text1 and Text3 boxes will not accept TAB keystrokes. When Text1 and Text3 have the focus, pressing the TAB key changes the focus to the next control in the tab order.

    1. Start a new project in Visual Basic. Form1 is created by default.
    2. Add three text boxes (Text1, Text2, and Text3) to Form1. Select the Text2 box and press the F4 key to display the Properties window. Set the MultiLine property of Text2 to True.

    NOTE: When you press the TAB key, single-line text boxes beep and do not accept the TAB keystroke, but multiLine text boxes do accept TAB keystrokes.
    3. Double-click the Text2 box to open the code window. Choose the GotFocus event from the Proc box. Add the following code to the Text2 GotFocus event:

    Code:
    Sub Text2_GotFocus ()
          ' When Text2 gets the focus, clear all TabStop properties on all
          ' controls on the form. Ignore all errors, in case a control does
          ' not have the TabStop property.
          On Error Resume Next
          For i = 0 To Controls.Count - 1   ' Use the Controls collection
             Controls(i).TabStop = False
          Next
       End Sub
    # NOTE: See the "Controls Collection" section below for an explanation of the Controls collection.
    4. Choose the LostFocus event from the Proc box. Add the following code to the Text2 LostFocus event:

    Code:
    Sub Text2_LostFocus ()
          ' When Text2 loses the focus, make the TabStop property True for all
          ' controls on the form. That restores the ability to tab between
          ' controls. Ignore all errors, in case a control does not have the
          ' TabStop property.
          On Error Resume Next
          For i = 0 To Controls.Count - 1   ' Use the Controls collection
             Controls(i).TabStop = True
          Next
       End Sub
    5. Start the program, or press the F5 key. Press the TAB key to give focus to Text2. Enter text into the Text2 box, pressing the TAB key as needed. Whenever Text1 or Text3 has the focus, pressing the TAB key moves the focus to the next control. Whenever Text2 has the focus, TAB keystrokes remain with the text in the text box. Close the form to end the program.

  4. #4
    Join Date
    May 2008
    Posts
    115

    Re: How do I create a textbox in vb that lets you insert tabs?

    Hi!

    You want to set two properties of the textbox:

    Multiline = True
    Tab Stop = False

    That should do it.

Similar Threads

  1. How to create Floating textbox?
    By Sanju!Ekta in forum Software Development
    Replies: 5
    Last Post: 15-07-2011, 10:45 AM
  2. Replies: 2
    Last Post: 20-08-2010, 01:23 AM
  3. How to create permanent Tabs in Firefox?
    By ramsun in forum Technology & Internet
    Replies: 5
    Last Post: 25-01-2010, 10:56 PM
  4. Replies: 5
    Last Post: 05-01-2010, 11:58 AM
  5. How to create Vertical Tabs in Visual studio 2008
    By Cisco-s in forum Software Development
    Replies: 3
    Last Post: 10-12-2009, 04:09 PM

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Page generated in 1,714,055,257.21365 seconds with 16 queries