JEHMayo Posted August 15, 2003 Posted August 15, 2003 I'm trying to figure out how many lines will display in a multiline textbox control. I've attempted to calculate it by using the GetHeight method of the textbox's Font object divided into the Height property of the textbox's ClientRectangle property. When I size the textbox to over 20 lines, the calculation doesn't work. It seems that the height actually used for each line in the textbox is a little more than what the font's GetHeight returns. I've also tried simply using the Height property of the font in the calculation. No luck there, either. ' My orginal code is like this: Dim cFont As Font = txtBox.Font Dim lineHeight As Single = cFont.GetHeight(txtBox.CreateGraphics()) Dim boxHeight As Single = txtBox.ClientRectangle.Height Dim maxLinesVisible As Decimal = boxHeight / lineHeight result is Decimal.Floor(maxLinesVisible) Is there some sort of metric that measures the height actually used for some spacing between the lines or something else???? :confused: Quote
*Experts* Nerseus Posted August 15, 2003 *Experts* Posted August 15, 2003 Try MeasureString (part of the Graphics object), which returns a SizeF object with the width and height. -Nerseus Quote "I want to stand as close to the edge as I can without going over. Out on the edge you see all the kinds of things you can't see from the center." - Kurt Vonnegut
JEHMayo Posted August 15, 2003 Author Posted August 15, 2003 You nailed it dead on: Dim g As Graphics = txtBox.CreateGraphics() Dim sf As SizeF = g.MeasureString(sLine, cFont, txtBox.Width) Then use sf.Height in the calculation. Thanks 1,000,000!:) Quote
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.