Page size & direction

4 posts, 0 answers
  1. Lynda Golomb
    Lynda Golomb avatar
    40 posts
    Member since:
    Dec 2009

    Posted 24 Mar Link to this post

    Hi, I'm evaluating this control.

    I'm opening a docx file in the control as a RadDocument. The file is right to left file and showing two pages on the screen in the wrong direction (page 1 on the left) - event when I change the control to RightToLeft=Yes (this only changes the scroll to the other side).

    I would like one of two options:

    1. Show only one page on the screen at a time (scroll down will go to second page). I found this can be done when making my window small but I'd like it to open maximized.

    2. Show two pages but in the correct direction (page 1 on the right and page 2 on the left).

    Any help?

    Thanks!!

  2. Hristo Merdjanov
    Admin
    Hristo Merdjanov avatar
    710 posts

    Posted 25 Mar Link to this post

    Hello Lynda,

    Thank you for writing.

    The scrolling behavior in RadRichTextEditor is controlled by its RadScrollBarElement. The step with which the control is scrolled is generally defined by the values of the LargeChange and SmallChange properties. They can be accessed this way: 
    this.radRichTextEditor1.RichTextBoxElement.VerticalScrollBar.LargeChange = 500;
    this.radRichTextEditor1.RichTextBoxElement.VerticalScrollBar.SmallChange = 50;

    I have also prepared a solution with manual handling of the scrolling. It would require utilizing the positioning API of RadRichTextEditor: Positioning. Please check my code snippet below: 
    public Form1()
    {
        InitializeComponent();
     
        this.radRichTextEditor1.RightToLeft = System.Windows.Forms.RightToLeft.Yes;
     
        this.radRichTextEditor1.Document = this.ImportDocx();
     
        this.radRichTextEditor1.RichTextBoxElement.VerticalScrollBar.MouseDown += VerticalScrollBar_MouseDown;
        this.radRichTextEditor1.RichTextBoxElement.VerticalScrollBar.ValueChanged += VerticalScrollBar_ValueChanged;
     
        this.radRichTextEditor1.RichTextBoxElement.VerticalScrollBar.LargeChange = 0;
        this.radRichTextEditor1.RichTextBoxElement.VerticalScrollBar.SmallChange = 0;
    }
     
    bool shouldHandleCustomScrolling;
    private void VerticalScrollBar_MouseDown(object sender, MouseEventArgs e)
    {
        shouldHandleCustomScrolling = true;
        RadScrollBarElement scrollBar = (RadScrollBarElement)sender;
        RadElement el = scrollBar.ElementTree.GetElementAtPoint(e.Location);
        if (el is ScrollBarButton)
        {
            ScrollBarButton btn = (ScrollBarButton)el;
            if (btn.Direction == ScrollButtonDirection.Up)
            {
                this.radRichTextEditor1.Document.CaretPosition.MoveToLastPositionOnPreviousPage();
            }
            else if (btn.Direction == ScrollButtonDirection.Down)
            {
                 this.radRichTextEditor1.Document.CaretPosition.MoveToFirstPositionOnNextPage();
            }
        }
        else if (el is RadScrollBarElement)
        {
            if (scrollBar.ThumbElement.BoundingRectangle.Y > e.Location.Y)
            {
                this.radRichTextEditor1.Document.CaretPosition.MoveToLastPositionOnPreviousPage();
            }
            else
            {
                this.radRichTextEditor1.Document.CaretPosition.MoveToFirstPositionOnNextPage();
            }
        }
    }
     
    int cachedValue = 0;
    private void VerticalScrollBar_ValueChanged(object sender, EventArgs e)
    {
        if (shouldHandleCustomScrolling)
        {
            if (cachedValue == 0)
            {
                cachedValue = this.radRichTextEditor1.RichTextBoxElement.VerticalScrollBar.Value;
            }
     
            if (cachedValue != 0 && cachedValue != this.radRichTextEditor1.RichTextBoxElement.VerticalScrollBar.Value)
            {
                this.radRichTextEditor1.RichTextBoxElement.VerticalScrollBar.Value = cachedValue;
                cachedValue = 0;
                shouldHandleCustomScrolling = false;
            }
        }
    }

    If I correctly understand your other question, you would like to have the editor showing the pages from right to left when it is zoomed out. Currently, that is not possible and RadRichTextEditor is following the behavior in MS Word which is the same.

    I hope this helps. Should you have further questions please do not hesitate to write back.

    Regards,
    Hristo Merdjanov
    Telerik
    Do you need help with upgrading your AJAX, WPF or WinForms project? Check the Telerik API Analyzer and share your thoughts.
  3. UI for WinForms is Visual Studio 2017 Ready
  4. Lynda Golomb
    Lynda Golomb avatar
    40 posts
    Member since:
    Dec 2009

    Posted 27 Mar in reply to Hristo Merdjanov Link to this post

    Thanks for the reply, but I think I have been misunderstood. I don't need to change the scroll - it's fine.

    Since change of direction is not possible I would like to be able to zoom out of the document and show one page at a time.

    My form opens maximized and it is therefore by default showing 2 pages at a time. 

    How can I show one page at a time?

  5. Hristo Merdjanov
    Admin
    Hristo Merdjanov avatar
    710 posts

    Posted 28 Mar Link to this post

    Hello Lynda,

    Thank you for writing back.

    The zoom factor in RadRichTextEditor is controlled by its ScaleFactor property. Please check if the solution as per the snippet below would bring the desired result: 
    private void radButton1_Click(object sender, EventArgs e)
    {
        this.radRichTextEditor1.Document.LayoutMode = DocumentLayoutMode.Paged;
        this.radRichTextEditor1.ScaleFactor = new Telerik.WinForms.Documents.Model.SizeF(1.5f, 1.5f);
        this.radRichTextEditor1.Document.SectionDefaultPageSize = PaperTypeConverter.ToSize(PaperTypes.A4);
    }

    A similar thread has also been discussed at our forums and I believe you could find it useful: http://www.telerik.com/forums/programmatically-zooming.

    I hope this helps. Please let me know if you need further assistance.

    Regards,
    Hristo Merdjanov
    Telerik
    Do you need help with upgrading your AJAX, WPF or WinForms project? Check the Telerik API Analyzer and share your thoughts.
Back to Top