问题
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.
回答1:
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.
回答2:
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; }
}
来源:https://stackoverflow.com/questions/2202478/richtextbox-caretposition-physical-location