简体   繁体   中英

Set current caretPosition in RichTextBox viewport end?

I already used the below code. It moves current caret position in viewport top.

FrameworkContentElement fce = (tpNextLine2.Parent as FrameworkContentElement);
if (fce != null)
{
    fce.BringIntoView();
}

I want to move current caretposition textpointer in richtextbox viewport end using WPF.

How can I achieve this?

If you don't want to change current caret position but scroll the WPF RichTextBox to move this position to the bottom of the visible area, you can use this code:

Rect rc = rtb.CaretPosition.GetCharacterRect(LogicalDirection.Forward);
rtb.ScrollToVerticalOffset(rc.Bottom + rtb.VerticalOffset - rtb.ViewportHeight);

Try this code :

RichTextBox1.Select(RichTextBox1.Text.Length - 1, 0);

RichTextBox1.ScrollToCaret();

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM