[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.
Re: Insert text at cursor location in textbox or selection.
Use the SelectedText property in either case.
Code:
TextBox1.SelectedText = "Z"
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"
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?
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
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. :afrog: