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

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

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