0

I'm using a RichTextBox class to make some automatic text formatting. And mz question is, how do I get the RichTextBox to put some string immediately after the caret. When I use RichTextBox.CaretPosition.InsertTextInRun("some string") the text is inserted after the current logical block, but I need to be insterted immediately after the caret, in the middle of a Run block. I hope it's clear, thx very much.

2 Answers2

0

Well, to insert text after the caret i would do this:

        richTextBox1.Select(richTextBox1.SelectionStart, 0);
        richTextBox1.SelectedText = "textToInsert";

If you provide additional information in your question i will attempt to fit my answer better.

caesay
  • 16,932
  • 15
  • 95
  • 160
  • The thing is, that I'm using the WPF RichTextBox (in System.Windows namespace), that doesn't have Select method. But the solition you suggest fits my problem, I just need it for the WPF RichTextBox. Thx for help. – Jan Kratochvil Feb 05 '10 at 07:59
0

I think you might have solved this issue by now, but I'll answer anyway.

This is what I used for a similar problem:

public string SelectionText
{
    get { return this.Selection.Text; }
    set { this.Selection.Text = value; }
}
Tahir
  • 11
  • 7