|
-
Feb 4th, 2006, 10:30 PM
#1
Thread Starter
Fanatic Member
[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.
-
Feb 4th, 2006, 10:36 PM
#2
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
-
Feb 4th, 2006, 10:41 PM
#3
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"
-
Feb 4th, 2006, 10:48 PM
#4
Thread Starter
Fanatic Member
Re: Insert text at cursor location in textbox or selection.
 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?
-
Feb 4th, 2006, 11:01 PM
#5
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
-
Feb 4th, 2006, 11:02 PM
#6
Re: Insert text at cursor location in textbox or selection.
 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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|