Windows.Forms RichTextBox Control - Avoid inserting large data.
Posted
by SchlaWiener
on Stack Overflow
See other posts from Stack Overflow
or by SchlaWiener
Published on 2010-04-15T12:43:07Z
Indexed on
2010/04/15
13:13 UTC
Read the original article
Hit count: 301
I have a Windows Form with a RichTextBox on it. The content of the RichTextBox is written to a database field that ist limited to 64k data. For my purpose that is way more than enough text to store.
I have set the MaxLength property to avoid insertng more data than allowed.
rtcControl.MaxLength = 65536
Howevery, that only restricts the amount of characters that so is allowed to put in the text. But with the formatting overhead from the Rtf I can type more text than I should be allowed to. It even get's worse if I insert a large image, which dosn't increase the TextLength at all but the Rtf Length grows quite a lot.
At the moment I check the Length of the richttextboxes' Rtf property in the FormClosing event and display a message to the user if it's to large. However that is just a workaround because I want to disallow putting more data than allowed into the control (like in a textbox if you exceed the MaxLength property nothing is inserted into the control and you hear the default beep().
Any ideas how to achive this?
I already tried:
using a custom control which extends the richtextbox and shadows th Rtf property to intercept the insertation. But it seems it isn't executed if I add text.
Even the TextChanged Event does not fire if I type smth. in the control.
© Stack Overflow or respective owner