This is a migrated thread and some comments may be shown as answers.

Highlighting and scrolling down via down key

1 Answer 51 Views
RichTextBox (obsolete as of Q3 2014 SP1)
This is a migrated thread and some comments may be shown as answers.
Ken
Top achievements
Rank 1
Ken asked on 04 Apr 2012, 06:59 PM
There appears to be an issue with the RichTextBox Editor when you highlight text and continue highlighting using the downkey. The textbox does not scroll down with your keypresses as it does when you are not highlighting. It will stay at the top and you can no longer track your highlighting below the visible area.

Thanks for continued excellence in support.

1 Answer, 1 is accepted

Sort by
0
Svett
Telerik team
answered on 09 Apr 2012, 12:29 PM
Hello Ken,

I managed to reproduce the issue. I added it to our public issue tracking system and it will be addressed in one of the next releases. Meanwhile, you can use the following workaround:

public class MyDocumentNavigator : DocumentNavigator
{
    public MyDocumentNavigator(DocumentView view)
        : base(view)
    {
 
    }
 
    public override bool ScrollToCaret()
    {
        IEditorCaret caret = this.DocumentView.Caret;
 
        RectangleF viewportBounds = this.DocumentView.ControlBoundingRectangle;
 
        if (caret == null || viewportBounds.IsEmpty)
        {
            return false;
        }
 
 
        RectangleF caretBounds = new RectangleF(caret.Position, new SizeF(caret.Width, caret.Height));
 
        float deltaX = 0;
        float deltaY = 0;
 
        if (caretBounds.Right > viewportBounds.Right)
        {
            deltaX = caretBounds.Right - viewportBounds.Width / 2;
        }
        else if (caretBounds.Left < viewportBounds.Left)
        {
            deltaX = caretBounds.Left - viewportBounds.Width / 2;
        }
 
        if (caretBounds.Top < viewportBounds.Top)
        {
            deltaY = caretBounds.Top - viewportBounds.Top;
        }
        else if (caretBounds.Bottom > viewportBounds.Bottom)
        {
            deltaY = caretBounds.Bottom - viewportBounds.Bottom;
        }
 
        IEditorScrollBar vScrollBar = this.DocumentView.Scroller.VScrollBar;
        IEditorScrollBar hScrollBar = this.DocumentView.Scroller.HScrollBar;
 
        hScrollBar.Value = DocumentScroller.ClampScrollBarValue(hScrollBar, hScrollBar.Value + (int)deltaX);
        vScrollBar.Value = DocumentScroller.ClampScrollBarValue(vScrollBar, vScrollBar.Value + (int)deltaY);
 
        return true;
    }
}

You should replace the default navigator by using the following code snippet:
this.richTextBox.DocumentView.Navigator = new MyDocumentNavigator(this.richTextBox.DocumentView);

I updated your Telerik points.

Kind regards,
Svett
the Telerik team
RadControls for WinForms Q1'12 release is now live! Check out what's new or download a free trial >>
Tags
RichTextBox (obsolete as of Q3 2014 SP1)
Asked by
Ken
Top achievements
Rank 1
Answers by
Svett
Telerik team
Share this question
or