RichTextBox and Inserting at Caret Positions

后端 未结 3 1194
感动是毒
感动是毒 2021-01-18 15:29

Here is the deal: I have a RichTextBox control and it works fine. The problem is that there is a button \"Insert Current DateTime\" which adds/injects the current datetime i

3条回答
  •  谎友^
    谎友^ (楼主)
    2021-01-18 15:52

    This worked for me:

    private void InsertText(String text, RichTextBox rtb)
    {
        rtb.CaretPosition = rtb.CaretPosition.GetPositionAtOffset(0, LogicalDirection.Forward);
        rtb.CaretPosition.InsertTextInRun(text);
    }
    

    I found the code here:

    How do I move the caret a certain number of positions in a WPF RichTextBox?

提交回复
热议问题