I have a C#/WinForms rich textbox for which I need to be able to limit the text entered to what visibly fits within the viewable area. I know I can limit it by number of characters, but this doesn’t achieve the desired effect when we consider things like word wrap, different character widths for non monospace fonts, etc.
I can have an event callback fire when the text changes, but I need a way to know the text is exceeding the viewable area. Any suggestions?
In your call back you can use MeasureString to determine the lenghth of the string given a font. Then you compare that to the textbox width.