Hello,
I am using the RadRichTextBox in a custom reporting solution in my application. I have a situation where the user has entered comments in rtf format in our application and I need to show these in a report. However, the comments may exceed the space on one page, so I need to detect the portion of the document that is visible within the bounds of the control and then split the document up over two or more pages, each with its own RadRichTextBox control.
When I check the CaretPosition at the end of the document the Y value on the Location property is less than the height of my control, but the text exceeds the bounds of the control when viewed.
Here is the code I am using:
DocumentPosition caretPos =
null
;
DocumentPosition endOfDocument =
null
;
var rtfText = myRtfText;
if
(rtfText !=
null
)
{
var provider =
new
RtfFormatProvider();
var radDocument = provider.Import(rtfText);
radDocument.SectionDefaultPageSize =
new
Size(maximumSize.Width, maximumSize.Height);
var radRichTextBox =
new
RadRichTextBox{Document = radDocument};
DocumentPosition tempPos = radRichTextBox.Document.CaretPosition;
tempPos.MoveToLastPositionInDocument();
endOfDocument =
new
DocumentPosition(tempPos);
caretPos = radRichTextBox.Document.CaretPosition;
caretPos.MoveToFirstPositionInDocument();
if
(caretPos != endOfDocument)
{
var start =
new
DocumentPosition(radRichTextBox.Document.CaretPosition);
while
(caretPos.Location.Y - start.Location.Y < maximumSize.Height)
{
if
(!radRichTextBox.Document.CaretPosition.MoveToCurrentLineEnd())
break
;
if
(!radRichTextBox.Document.CaretPosition.MoveNext())
break
;
}
if
(caretPos.Location.Y - start.Location.Y > maximumSize.Height)
{
// Back up so the content fits within the range
radRichTextBox.Document.CaretPosition.MoveToLastPositionInPreviousParagraph();
}
var docSelection =
new
DocumentSelection(radRichTextBox.Document);
docSelection.SetSelectionStart(start);
docSelection.AddSelectionEnd(caretPos);
var docFragment =
new
DocumentFragment(docSelection);
var newDoc =
new
RadDocument();
var editor =
new
RadDocumentEditor(newDoc);
editor.InsertFragment(docFragment);
var rtfSegment = provider.Export(newDoc);
}
}
Also, attached is an image of the report with the control on it, clearly showing that there is text beyond the bottom of the control.
Any insight you could offer would be appreciated.
Thanks,
Peter