Results 1 to 8 of 8

Thread: Insert text into a text box.[RESOLVED]

  1. #1

    Thread Starter
    Junior Member Morgoth's Avatar
    Join Date
    Mar 2005
    Posts
    20

    Resolved Insert text into a text box.[RESOLVED]

    Hello,

    I am trying to figure out how to insert a line of text into a text box where the cursor is located.

    Insert "Hello World" into a textbox.
    Text Box = "This is so|me text"
    | = Cursor
    Inserted Text Box = "This is soHello Worldme text"

    My first idea is to store the text before the cursor into a variable and the text after the cursor into another variable.
    To insert the text I just:
    VB Code:
    1. textbox.text = strTextBeforeCursor & strTextInsert & strTextAfterCursor

    Anyone else think there is an easier idea?


    Thanks for your input!
    Last edited by Morgoth; Apr 4th, 2005 at 05:30 PM. Reason: [RESOLVED]

  2. #2
    PowerPoster RhinoBull's Avatar
    Join Date
    Mar 2004
    Location
    New Amsterdam
    Posts
    24,132

    Re: Insert text into a text box.

    Try this very simple approach first:
    VB Code:
    1. Private Sub Command1_Click()
    2. Dim pos%
    3.  
    4.     pos = Text1.SelStart 'get current cursor position
    5.     Text1.Text = Left(Text1.Text, pos) & "_ABC_" & Mid(Text1.Text, pos + 1)
    6.  
    7. End Sub

  3. #3
    G&G Moderator chemicalNova's Avatar
    Join Date
    Jun 2002
    Location
    Victoria, Australia
    Posts
    4,246

    Re: Insert text into a text box.

    Why bother finding where the Cursor is, when SelStart is where it is anyway?
    VB Code:
    1. TextBox.SelText = "Hello World"
    Phreak

    Visual Studio 6, Visual Studio.NET 2005, MASM

  4. #4

  5. #5
    G&G Moderator chemicalNova's Avatar
    Join Date
    Jun 2002
    Location
    Victoria, Australia
    Posts
    4,246

    Re: Insert text into a text box.

    I realise I sounded a bit annoyed in my previous post. My bad

    We're all happy here..

    Phreak

    Visual Studio 6, Visual Studio.NET 2005, MASM

  6. #6

  7. #7

    Thread Starter
    Junior Member Morgoth's Avatar
    Join Date
    Mar 2005
    Posts
    20

    Resolved Re: Insert text into a text box.[RESOLVED]

    I am all smiles here!
    :mike:

    Thanks for taking the time to answer a stupid question
    (so easy)

  8. #8

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