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

Page size & direction

5 Answers 205 Views
RichTextEditor
This is a migrated thread and some comments may be shown as answers.
Lynda Golomb
Top achievements
Rank 1
Lynda Golomb asked on 24 Mar 2016, 01:23 PM

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!!

5 Answers, 1 is accepted

Sort by
0
Hristo
Telerik team
answered on 25 Mar 2016, 10:59 AM
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.
0
Lynda Golomb
Top achievements
Rank 1
answered on 27 Mar 2016, 10:13 AM

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?

0
Hristo
Telerik team
answered on 28 Mar 2016, 11:54 AM
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.
0
rosa
Top achievements
Rank 1
answered on 09 Dec 2016, 02:59 PM

Hello guys

I've used above code for setting the page size and it s work but after this below code is used the page size dosen't work

radRichTextEditor1.Document=doc;

it means that when the text are entered in Radrichtext all of setting dont work

Please help me how i can fix it

tnx.

0
Hristo
Telerik team
answered on 12 Dec 2016, 12:23 PM
Hi Rosa,

Thank you for writing.

After loading the document you can change the page size by executing a ChangePaperTypeCommand. Please check my code snippet below: 
this.radRichTextEditor1.Document.SectionDefaultPageSize = PaperTypeConverter.ToSize(Telerik.WinForms.Documents.Model.PaperTypes.A0);
RadDocument document = null;
IDocumentFormatProvider provider = new DocxFormatProvider();
using (Stream stream = File.OpenRead(@"..\..\doc.docx"))
{
    document = provider.Import(stream);
}
 
this.radRichTextEditor1.Document = document;
ChangePaperTypeCommand command = new ChangePaperTypeCommand(this.radRichTextEditor1.RichTextBoxElement);
command.Execute(Telerik.WinForms.Documents.Model.PaperTypes.A0);

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

Regards,
Hristo
Telerik by Progress
Telerik UI for WinForms is ready for Visual Studio 2017 RC! Learn more.
Tags
RichTextEditor
Asked by
Lynda Golomb
Top achievements
Rank 1
Answers by
Hristo
Telerik team
Lynda Golomb
Top achievements
Rank 1
rosa
Top achievements
Rank 1
Share this question
or