4 Answers, 1 is accepted
RadRichTextBox does not have a MaxLength property, as it uses format providers to import and export its document and depending on the format you choose, the size of the exported document differs. Besides, it is not quite clear how tables, pictures, UI elements embedded in the document should be counted.
We are considering implementing a TextBox-like control and it can have a property like that, however, the exact form is still not certain. Could you elaborate on your scenario? Does the text you are previewing/editing have any formatting and why do you need to limit the length of the content?
Iva
the Telerik team
Register for the Q2 2011 What's New Webinar Week. Mark your calendar for the week starting July 18th and book your seat for a walk through of all the exciting stuff we will ship with the new release!
private
void
OnDocumentContentChanged(
object
sender, EventArgs e)
{
var noteText =
new
TxtFormatProvider().Export(Document);
var document = (sender
as
RadDocument);
if
(noteText.Length > MaxLength && document !=
null
)
{
document.DocumentContentChanged -= OnDocumentContentChanged;
document.CaretPosition.MoveToLastPositionInDocument();
document.Selection.SetSelectionStart(document.CaretPosition);
for
(
int
i = 0; i < noteText.Length - MaxLength; ++i)
{
document.CaretPosition.MoveToPrevious();
}
document.Selection.AddSelectionEnd(document.CaretPosition);
_radRichTextBox.Delete(
false
);
document.DocumentContentChanged += OnDocumentContentChanged;
}
}
I originally started looking through the forums today because I noticed there is a DocumentChanging event in the RadRichTextBox, and I was curious if there were a way I could handle the content coming in before the document is changed. Our current method leaves a flicker of text past what our max length. Is there a way to get a hold of the new input on the DocumentChanging event?
Aside from that, in your earlier post you mentioned a possible text box like control. What would this entail? Is it still a possibility?
Thanks for your help,
Mike
The DocumentChanging event is fired when you are assigning a new document to the Document property of RadRichTextBox or when you change the value of the property that RadRichTextBox's content is bound to (through a data provider). Therefore, it will not be applicable in your scenario.
Unfortunately, currently there is no way to limit the content of RadRichTextBox at this point. We have logged this feature and will consider implementing it in one of the following releases.
Iva Toteva
the Telerik team