views:

222

answers:

1

Hi, I'm trying to make my own control in for .NET using VB and I'm having problems achieving what I want to do. In fact, I'm making a control which inherit from the textbox class and the only modification I'm trying to bring to it is that if the control is visibly full, the user can't type anymore. So:

  • Scrollbars should never appear.
  • The extended TextBox may be multiline or singleline.
  • The extended TextBox may have different fonts and font sizes.

Right now, the technique i'm using is graphics.measurestring to get a sizeF containing the width and the height of my string to compare it to the height and width of my textbox control. All this in the KeyDown event (I don't know of it's the best solution). I can get it to work fine for the width but I can't seem to ge the height right in a multiline textbox. If anyone has ever worked with this stuff, I'd need some explanation on how it should be done. Thank you.

A: 

The problem is your third requirement:

The extended TextBox may have different fonts and font sizes.

What this means is that you will have to figure out how tall each line is by which characters in the line have the largest font size, and to know that, you will have to also know which characters are in each line. It gets worse, because (surprisingly) different fonts can have different heights given the same point size. That all might be workable, if it weren't for the fact that each character in a proportionally-spaced font is a different width.

And if you intend to support superscripts and subscripts...

Robert Harvey