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

How to limit RichTextEditor to 1 page

4 Answers 64 Views
RichTextEditor
This is a migrated thread and some comments may be shown as answers.
Laurent
Top achievements
Rank 1
Laurent asked on 23 Aug 2016, 03:29 PM

Hi,

 

I am looking for a way to limit the RichTextEditor to only one page.

The user must not be able to enter more text than can fit one a single page.

 

Thanks in advance!

Laurent

4 Answers, 1 is accepted

Sort by
0
Dess | Tech Support Engineer, Principal
Telerik team
answered on 24 Aug 2016, 08:26 AM
Hello Laurent,

Thank you for writing. 

There is not a built-in method for limiting the user to 1 page. However, note that you can handle the user input by subscribing to the CommandExecuting event and if the current page index is greater than 1 you can cancel the event. Here is a sample code snippet for handling text input:
public Form1()
{
    InitializeComponent();
 
    this.radRichTextEditor1.LayoutMode = DocumentLayoutMode.Paged;         
    this.radRichTextEditor1.CommandExecuting += radRichTextEditor1_CommandExecuting;
}
 
private void radRichTextEditor1_CommandExecuting(object sender, Telerik.WinForms.Documents.RichTextBoxCommands.CommandExecutingEventArgs e)
{
    if (e.Command is InsertTextCommand)
    {
        var index = (this.radRichTextEditor1.RichTextBoxElement.ActiveEditorPresenter as DocumentPrintLayoutPresenter).GetCurrentPage();
        if (index > 1)
        {
            e.Cancel = true;
        }
    }
}

I hope this information helps. Should you have further questions I would be glad to help.

Regards,
Dess
Telerik by Progress
Check out the Windows Forms project converter, which aids the conversion process from standard Windows Forms applications written in C# or VB to Telerik UI for WinForms.For more information check out this blog post and share your thoughts.
0
Laurent
Top achievements
Rank 1
answered on 24 Aug 2016, 02:18 PM

Hello Dess,

thank you for your fast response.

Unfortunately, the solution you posted will not work in all cases. If the user inserts content on the first page it can occur that the following content is pushed to the second page.Your solution does not address these cases.

Is there any event which is fired when content breaks to a new page? Any other solutions?

 

Regards,

Laurent

0
Accepted
Dess | Tech Support Engineer, Principal
Telerik team
answered on 25 Aug 2016, 08:55 AM
Hello Laurent, 

Thank you for writing back. 

As it was already noted in my previous post, there is not a specific event that is fired when the content jumps to a new page.

RadRichTextEditor uses different commands for manipulating the document. Hence, the CommandExecuting event is fired for different types of commands. It is up to you which commands to cancel when pages number is increased. However, some of the insert commands, e.g. InsertPictureCommand, are triggered before the image is actually inserted in the document.

An alternative solution that I can suggest is to subscribe to the CommandExecuted event and make undo of the last insert operation that exceeds the pages limit: 
private void radRichTextEditor1_CommandExecuted(object sender, CommandExecutedEventArgs e)
{
     if (this.radRichTextEditor1.Document.FirstLayoutBox.ChildLayoutBoxes.Count > 1)
         {
                this.radRichTextEditor1.Undo();
                MessageBox.Show("The document must be one page.");
         }
}

I hope this information helps. If you have any additional questions, please let me know.

Regards,
Dess
Telerik by Progress
Check out the Windows Forms project converter, which aids the conversion process from standard Windows Forms applications written in C# or VB to Telerik UI for WinForms.For more information check out this blog post and share your thoughts.
0
Laurent
Top achievements
Rank 1
answered on 25 Aug 2016, 12:26 PM

Great!

This was exactly what I was looking for!

Thank you for your help!

Tags
RichTextEditor
Asked by
Laurent
Top achievements
Rank 1
Answers by
Dess | Tech Support Engineer, Principal
Telerik team
Laurent
Top achievements
Rank 1
Share this question
or