Textheight & Textwidth problem in vb6

My problem is that I have several textboxes on the screen with different fonts in them and I need to evaluate there true lenght and height so as I can print them at correctly justified positions on the printers object. It seems very obvious how you should do this using the above commands but they always return the same height and width for totally different fonts. The fonts are showing to be different in the textboxes but there values stay the same on height no matter what fontsize you change them to.
waynecarlisleAsked:
Who is Participating?

[Webinar] Streamline your web hosting managementRegister Today

x
 
caraf_gConnect With a Mentor Commented:
The problem is that the TextHeight and TextWidth values depend on the font of your Form regardless of which text box you use.

There is a very easy way you could fix this:

1 Stick a picture box on the form, with border style set to none so you don't see it at run time. PS - make sure you set the tabstop property to false as well so the user can't tab into it.

2 For every text box for which you want to know the correct text height or text width:
Set Picture1.Font = Text1.Font
The text width and text height for the text in the text box can then be calculated using the TextWidth and TextHeight methods on the picture box:
correct text width = Picture1.TextWidth(Text1.Text)

0
 
waynecarlisleAuthor Commented:
Adjusted points to 100
0
 
waynecarlisleAuthor Commented:
caraf

Thanks,

I have spent 2 full days working on this

Wayne
0
All Courses

From novice to tech pro — start learning today.