0

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?

2 Answers 2

3

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

Sign up to request clarification or add additional context in comments.

1 Comment

The Paste method is nice because it maintains the undo buffer
0

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.

1 Comment

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

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.