tags:

views:

37

answers:

2

Ok, I'm writing a program in vb. It's simply a text editor. However i've run into a little snag. My program has options to click a button and text is inserted into the text box. I am using this line:

textbox.AppendText (sometext)

Now this code works great if i want the text to be added at the bottom of the page. So here's my question, is there any way to modify or maybe replace this code so that the text is inserted were the cursor is?

+3  A: 

Try setting .SelectedText property or using .Paste(String).

GSerg
The `Paste` method is nice because it maintains the undo buffer
Daniel LeCheminant
+1 Didn't know that. Thanks.
Wade73
.selectedText worked like a charm. thanks!
Tony C
A: 

Not through the textbox control itself, as far as I know. You will need to use the SelectionStart property to manually insert the text.

textBox1.Text = textBox1.Text.Substring(0, textBox1.SelectionStart) & "INSERTEDTEXT" & textBox1.Text.Substring(textBox1.SelectionStart)

This is assuming you want to insert the text and not just replace it.

bryanjonker
Actually the SelectedText property doesn't have to replace text. Any where the cursor is, it will insert the text.
Tony C