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!

Font properties 1

Status
Not open for further replies.

wanmaster

Programmer
Nov 20, 2000
94
NL
Anyone knows how to find out the width of a specific character or some text when using a non-preformatted font? For example: the "i" takes up less pixels then the "w".

Remedy
 
Although there are API calls to allow you to do this you don't need them in VB. Form's have a TextWidth property. So. for example, just have a hidden form with it's scalemode set to pixels and then something like the following:
[tt]
Option Explicit

Private Sub Command1_Click()
Debug.Print GetTextPixelWidth("i", Text1)
End Sub

Private Function GetTextPixelWidth(strText As String, SourceControl As Control) As Single
Set HiddenForm.Font = SourceControl.Font
GetTextPixelWidth = HiddenForm.TextWidth(strText)
End Function
 
Thanx, I never knew..
I stayed up all night eating too much pizza and neglecting my girlfriend, figuring out a way (using an enormous amount of code), while the answer was so easy!

Thanx again!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top