I haven't totally thought this through and I don't know all your reqirments,
however, have you considered overriding the KeyPress event. In this event,
measure the length of the string and add line break characters when the
string gets to the length of the textbox.
I don't know the exact syntax but I think it woud go something like this.
In your custom textbox control load
- Get a graphics object from the textbox.
- Calculate the size of a single character ('M')
- Determine how many characters can fit into the textbox based on the
textbox size.
In the override for KeyPress
- Insert line breaks every so many characters as determined in the load.
I say to calculate the size of 'M' in the constructor to provide better
performance, however, if you have a line of 'i's and a line of 'M''s the
line of 'i's will be much shorter. So you may need to do the size
calculation in the KeyPress. Loop through each character calcualting the
cumulative length. When the cumulative length exceeds the length of the
textbox insert a line break.
Let me know how this worked out. I am curious if there is a big performance
hit for recalculating the size on the KeyPress.
--
Tom Krueger
My Blog -
http://weblogs.asp.net/tom_krueger
Smart Client DevCenter -
http://msdn.microsoft.com/smartclient/
Mobile DevCenter -
http://msdn.microsoft.com/mobility
This posting is provided "as is" with no warranties and confers no rights.