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 Shaun E on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

vb6 Get font width metrics

Status
Not open for further replies.

JimHilton

IS-IT--Management
Jun 20, 2009
346
CA
Hi, I thought this would be a piece of cake but its turning out to be quite the mystery.

I am writing a program that needs to know the font width of any character added to the text box.

I'm using the text onchange event.

I need the font width's width in points

I've tried the the picture box route, but am not comfortable with it and i need to evaluate 4 text boxes with different sized fonts.

Edit: Posted in correct forum and was previously asked "How come I am not comfortable with the picbox method."

Not sure really, it just seems to me that there is some type of .OCX out there or...

Thanks!
 
I'm still unclear as to why you'd prefer to find an external 3rd party OCX to provide this information when you can already do it extremely easily in VB using built-in functionality

Without understanding what your objections are it is difficult to advise an alternative.

It migth also be useful for us to know why you need to measure the width, as this might help guide us to the most apprpriate solution (if we do indeed conclude that the picturebox method is unsuitable ... )

 
Hi Jim,

I suggest you try strongm's code from thread222-1036091
I think it just might be what you need.
:)

[navy]"We had to turn off that service to comply with the CDA Bill."[/navy]
- The Bastard Operator From Hell
 
Hi, i am working on a program that will take data that is manually imput and then will get flowed into a tabloid page.

I need to determine the width of a column that is 114 points wide. (But this will change depending on the lyaout).

If the picbox is the best route to go and is reliable at returning a font width then I guess I can go with the existing code I have.

I'll check out the link tho just to see.

Thanks!

 
> reliable at returning a font width

Why would you think that it is not? Hve you had issues?

>I'll check out the link

The link is to my code, which uses the GetTextExtentPoint32 API - which is basically exactly what is wrapped by VB's TextWidth method.
 
Thanks for your input, but now i think i've open yet another can of worms.

VB6 appears to support the command TextWidth Method

I set the scale mode to 2 (points),

This also seems to work as well.

But from the MSDN library it seems to refer to this method for creating reports etc.

Thanks again!!

Jim
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top