Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Change size of text box to match size of selected font 1

Status
Not open for further replies.

PurpleUnicorn

Programmer
Mar 16, 2001
79
US
Is there a way to change the height of a textbox on a form based on the fontsize selected from a combobox on the same form?

I want to do a preview of a font and font size right on my form, but I can't figure out how to get the textbox for my preview to be the right "size to fit" the selected font. The height of the textbox will need to change each time a font is selected.

Thanks,

Nancy
 
The textbox has Heigth and Width properties. You're going to have to change them programatically to correspond with the Font Size. I'm not sure what the exact conversion from points to inches is, but you'll need to calculate it in order to set the size properties.
 
That's the part I don't know - points to inches (or twips).
Thanks anyway.

Nancy
 
Multiply the number of points in your font by twenty to realize the number of twips high you need, you may need to add an extra point for "breathing room".

MyTextBox.Height = PointSize x 20 'PointSize being your font size

HTH Joe Miller
joe.miller@flotech.net
 
I tried to multiply pointsize by 20. I used Arial 6 - so according to this calculation, the height is 120 twips (or .08333 inches - 120/1440). I set my textbox.height = .0833 inches(I did this from design view just to test) and the bottom of the text is truncated.
Do you know of some other way to determine the minimum height needed for a particular font/size?

Thanks,

Nancy
 
Add extra points for breathing room:

MyTextBox.Height = (PointSize + 2) x 20

Joe Miller
joe.miller@flotech.net
 
Thanks a bunch Joe. I must have missed the part about adding the extra point in your original post. I actually had to add 3 point - but it works great. Thanks again.

Nancy
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top