• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 261
  • Last Modified:

Finding the width of a printed character with a specific font in Visual Basic 6

I use to know how to do this but I forgot...

How do you find the width of a character to be printed on a form in visual basic using the form's font? For Instance, finding how many x-pixels are required to write the letter "w" to the form.

And will this tell me just the exact width of the character (like where the edge of the black starts to where it ends), or the amount of space required to write the next character?

Thanks.
0
Sid_The_Kid
Asked:
Sid_The_Kid
  • 3
  • 2
1 Solution
 
PaulHewsCommented:
This will calculate the width of the shown string in pixels:

Me.TextWidth("This is the string") / Screen.TwipsPerPixelX
0
 
Sid_The_KidAuthor Commented:
Hey thanks. I never even knew about the "Screen.TwipsPerPixelX" I just multiplied everything by 20 ><

I'll test this out...
0
 
PaulHewsCommented:
>I just multiplied everything by 20

Well, close.  It's typically 15 on most systems.
0
 
Sid_The_KidAuthor Commented:
lol I knew it was either 15 or 20 :)
I usually just try both and see which one works better!

Alright Thanks for the help here are the points!
0
 
PaulHewsCommented:
You're welcome.  Thanks for the points.  :)

>Lol I knew it was either 15 or 20 :)
>I usually just try both and see which one works better!

The reason for the TwipsPerPixelX and Y properties is because this value can actually change depending on the DPI that someone has set for their video adapter...  So what works for you might cause a problem for someone installing your program.  Thus it's better to use the provided conversion.  :)

0

Featured Post

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

  • 3
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now