[英]RichTextBox CaretPosition physical location
I'm using a RichTextBox class to make some automatic text formatting. 我正在使用RichTextBox类进行一些自动文本格式设置。 And mz question is, how do I get the RichTextBox to put some string immediately after the caret.
而mz问题是,如何让RichTextBox在插入符号后立即放置一些字符串。 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.
当我使用RichTextBox.CaretPosition.InsertTextInRun(“ some string”)时,在当前逻辑块之后插入文本,但是我需要在插入符号后立即插入Run块中间。 I hope it's clear, thx very much.
我希望很清楚,非常感谢。
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. 如果您在问题中提供其他信息,我将尝试更好地适合我的答案。
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; }
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.