WPF向richtextbox光标处插入指定文本

private void InsertText(RichTextBox tb, string text)
{
tb.CaretPosition.InsertTextInRun(text);
if (tb.CaretPosition.LogicalDirection == LogicalDirection.Backward)
{
TextPointer tp = tb.CaretPosition.GetPositionAtOffset(text.Length, LogicalDirection.Forward);
if (tp != null)
{
tb.CaretPosition = tp;
}
}

}

posted @ 2021-12-07 16:01  奇迹之耀  阅读(197)  评论(0编辑  收藏  举报