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

From Points to Pixels!

Status
Not open for further replies.

AndyGroom

Programmer
May 23, 2001
972
GB
I need to show a preview within a PictureBox on screen of how a font will look at a specific pixel size rather than point size. Since the font property only supports point sizes, how can I create an acurate preview?

- Andy
___________________________________________________________________
If you think nobody cares you're alive, try missing a couple of mortgage payments
 
I think this covers it:
Code:
Private Function PixelsToPoints(ByVal Pixels As Long) As Single
    PixelsToPoints = (Pixels * Screen.TwipsPerPixelY) / 20
End Function

Private Function PointsToPixels(ByVal Points As Single) As Long
    PointsToPixels = (Points / Screen.TwipsPerPixelY) * 20
End Function
Verify this, but I think it is corerct.
 
Just out of interest, why 20?

- Andy
___________________________________________________________________
If you think nobody cares you're alive, try missing a couple of mortgage payments
 
Or
Code:
[blue]
Private Function msPixelsToPoints(ByVal Pixels As Long) As Single
    msPixelsToPoints = ScaleY(Pixels, vbPixels, vbPoints)
End Function

Private Function msPointsToPixels(ByVal Points As Single) As Long
    msPointsToPixels = ScaleY(Points, vbPoints, vbPixels)
End Function[/blue]


>Just out of interest, why 20?

Because the number of twips per inch is 1440, and the number of points per inch is 72 ...

 
Good point strongm, that's why we have the ScaleY() method already - so we don't need to reinvent the process as I did above.
 
Yes, or expressing the same thing another way: there are 20 twips per point, i.e. a twip is 1/20th of a point.
 
ScaleY doesn't seem to work in VB6.

- Andy
___________________________________________________________________
If you think nobody cares you're alive, try missing a couple of mortgage payments
 
Works absolutely fine in my VB6.

It is, however, a form method, not a VBA function
 
Ah ok. I hadn't used it before and I assumed it worked as listed in your code.

- Andy
___________________________________________________________________
If you think nobody cares you're alive, try missing a couple of mortgage payments
 
Hmm...
Code:
Private Function msPixelsToPoints(ByVal Pixels As Long) As Single
With New Form
    msPixelsToPoints = .ScaleY(Pixels, vbPixels, vbPoints)
End With
End Function

Private Function msPointsToPixels(ByVal Points As Single) As Long
With New Form
    msPointsToPixels = .ScaleY(Points, vbPoints, vbPixels)
End With
End Function
Can't test this where I am. Does it work?
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top