views:

502

answers:

1

I have a multi-line textbox that typically displays very long strings (license agreements, for example), and a requirement around the display is that if the user "pages" through the text via the vertical scrollbar (not clicking the arrows or the scroll box, but clicking above or below the scrollbox), on the last "page" the first line must be the last line from the previous page, and the text is padded with blanks lines to accommodate this.

I know I can get the size of the string, and the number of lines in the textbox, but is it possible to retrieve the number of lines displayed in the textbox at one time so I can calculate how much the text will need to be padded? Looking at the list of messages I can send via P/Invoke, I don't see one to request the number of displayed lines.

+2  A: 

You could get the maximum number of lines displayed at one time by calculating the font height and devide the textbox height by that.

Just an idea... Not sure if it will come out correct, but you could do some tests and see if it matches.

To get the font Height:

public SizeF MeasureString( string text, Font font )

Stormenet
This is a good start. There's apparently a bit of padding at the top and bottom, so the math isn't exact. I need to try with different sized textboxes to see how it pans out.
bjanaszek
Glad I could help :)
Stormenet