arjun sanju
arjun sanju

Reputation: 135

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?

Upvotes: 0

Views: 502

Answers (2)

Fratyx
Fratyx

Reputation: 5797

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);

Upvotes: 1

Nakul Chaudhary
Nakul Chaudhary

Reputation: 26174

Try this code :

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

RichTextBox1.ScrollToCaret();

Upvotes: 0

Related Questions