Results 1 to 6 of 6

Thread: [RESOLVED] Insert text at cursor location in textbox or selection.

  1. #1

    Thread Starter
    Fanatic Member
    Join Date
    Jul 2003
    Posts
    830

    Resolved [RESOLVED] Insert text at cursor location in textbox or selection.

    Hello,

    I have a textbox which (for example) has the text "abc123" in it. I would like to be able to do two things. One...is .... If I click my mouse between the "abc" and the "123", I would like to press a button and insert the letter "Z". So the resultant would look like this "abcZ123". Two...I would like to be able to select part of the text in the textbox..(for example the "ab" part and then press the button and insert the letter "Z"...so the resultant would look like this "Zc123".

    I believe this has to do with .selectionstart...but....I have not been able to figure it out yet.

    Thanks for any directions.

  2. #2
    The Devil crptcblade's Avatar
    Join Date
    Aug 2000
    Location
    Quetzalshacatenango
    Posts
    9,091

    Re: Insert text at cursor location in textbox or selection.

    Use the SelectedText property in either case.

    Code:
    TextBox1.SelectedText = "Z"
    Laugh, and the world laughs with you. Cry, and you just water down your vodka.


    Take credit, not responsibility

  3. #3
    Frenzied Member Phill64's Avatar
    Join Date
    Jul 2005
    Location
    Queensland, Australia
    Posts
    1,201

    Re: Insert text at cursor location in textbox or selection.

    to further explain, you would first select the portion u want

    eg:
    textbox1.select(0,1) 'would select the first letter
    textbox1.selectedtext = "a" 'changes first letter to a

    so to do your "abc123" to "abcZ123" example
    textbox1.select(3,0)
    textbox1.selectedtext = "Z"

  4. #4

    Thread Starter
    Fanatic Member
    Join Date
    Jul 2003
    Posts
    830

    Resolved Re: Insert text at cursor location in textbox or selection.

    Quote Originally Posted by crptcblade
    Use the SelectedText property in either case.

    Code:
    TextBox1.SelectedText = "Z"
    This seems to work. Any reason not to do it this way?

  5. #5
    Frenzied Member Phill64's Avatar
    Join Date
    Jul 2005
    Location
    Queensland, Australia
    Posts
    1,201

    Re: [RESOLVED] Insert text at cursor location in textbox or selection.

    well, i misunderstood your question, you want to insert where the mouse is. that's fine then.

    only flaw would be if you highlight any characters, this will replace those characters, if u do not want that to occur, make .selectionlength = 0

  6. #6
    The Devil crptcblade's Avatar
    Join Date
    Aug 2000
    Location
    Quetzalshacatenango
    Posts
    9,091

    Re: Insert text at cursor location in textbox or selection.

    Quote Originally Posted by birthjay
    Any reason not to do it this way?
    Only if you want to do it wrong.
    Laugh, and the world laughs with you. Cry, and you just water down your vodka.


    Take credit, not responsibility

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