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

RichTextBox limit input to view area

5 Answers 27 Views
RichTextBox
This is a migrated thread and some comments may be shown as answers.
Stefan
Top achievements
Rank 1
Stefan asked on 03 Sep 2019, 07:54 AM

Hi,

I have a program that imitates a physical sheet of paper, with an area that the user can input information. For the input area I'm using a RichTextBox, so the user can paste images, format etc. However, as the page is to be printed on a single piece of paper I want to limit the amount the user can enter. I've disabled the scrollbars so the user cannot scroll up and down, but they can still keep typing as if the document was infinite and the text just disappears. Is there any way to limit the input to only the visible area?

5 Answers, 1 is accepted

Sort by
0
Tanya
Telerik team
answered on 05 Sep 2019, 09:06 AM

Hi Stefan,

You could achieve a similar behavior using the layout boxes generated to show the content. To obtain the last layout box inside the document after editing the content, you would need to subscribe to the DocumentContentChanged event of RadRichTextBox. Once you have found the last layout box, you can compare its Bottom position with the size of the control to find whether the content exceeds the allowed size. If so, invoke the Undo() method to cancel the last change. Here is an example in code:

private void RadRichTextBox_DocumentContentChanged(object sender, EventArgs e)
{
    Paragraph lastParagraph = this.radRichTextBox.Document.EnumerateChildrenOfType<Paragraph>().Last();
    bool isContentLonger = lastParagraph.LastLayoutBox.BoundingRectangle.Bottom > this.radRichTextBox.RenderSize.Height;
    if (isContentLonger)
    {
        this.radRichTextBox.Undo();
    }
}

Hope this is helpful.

Regards,
Tanya
Progress Telerik

Get quickly onboarded and successful with your Telerik and/or Kendo UI products with the Virtual Classroom free technical training, available to all active customers. Learn More.
0
Stefan
Top achievements
Rank 1
answered on 22 Sep 2019, 03:09 AM

Hi,

Thanks for that. It seems to mostly work. Couple little of funny things when pasting images that it seems to remove the last 2 pastes rather than just the one, however it works well enough that it prevents the user from editing outside of the visible area.

Thanks.

0
Tanya
Telerik team
answered on 25 Sep 2019, 04:26 PM

Hi Stefan,

Thank you for sharing your feedback.

I tested the behavior with the images but it seems like everything is working as expected. Can you please share the steps and content you are pasting so I can ensure I am testing the same scenario? I am trying to reproduce the issue so I can investigate it and try to provide you with a solution for it.

Regards,
Tanya
Progress Telerik

Get quickly onboarded and successful with your Telerik and/or Kendo UI products with the Virtual Classroom free technical training, available to all active customers. Learn More.
0
Stefan
Top achievements
Rank 1
answered on 26 Sep 2019, 09:14 AM

I just tried it again and couldn't reproduce what I did the first time. Even when the issue occurred it wasn't a big deal and something of a fringe case. I'm happy with the result you have given me and implemented it into the application

0
Tanya
Telerik team
answered on 26 Sep 2019, 02:53 PM

Hi Stefan,

I am happy to hear that the suggestion helped you. In case you notice something strange in the behavior of the control, please let us know.

Regards,
Tanya
Progress Telerik

Get quickly onboarded and successful with your Telerik and/or Kendo UI products with the Virtual Classroom free technical training, available to all active customers. Learn More.
Tags
RichTextBox
Asked by
Stefan
Top achievements
Rank 1
Answers by
Tanya
Telerik team
Stefan
Top achievements
Rank 1
Share this question
or