RichTextBox CaretPosition physical location

戏子无情 提交于 2019-12-12 04:49:43

问题


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

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!