westconn1: Thanks for responding
Got It:
It APPEARS that ALL controls (except Form and Picturebox) create their Fonts when they gain Focus.
and destroy them when the control looses focus. Hence the Font does Not exist on the controls device context,
so the information is not avaialbe without reinstalling the Font on the DC..
Here's an example:
Code:
Private Sub GetFontHeight()
'--------------------------------
Dim hDC As Long
Dim hWnd As Long
Dim strFontName As String
Dim lngFontSize As Long
'Individual Font Variables
Dim mymetrics As TEXTMETRIC
Dim InternalLeading As Single
Dim Ascent As Single
Dim Descent As Single
Dim ExternalLeading As Single
Dim iHeight As Integer
Dim VerifyFSizePoints As Single
Dim VerifyHeightPixels As Integer
'********
'STARTUP
'********
'------------------------------
'Get the New Font Data
'---------------------------
strFontName = "Tahoma"
lngFontSize = 48
'--------------------------------------
'Get the Controls Device Context
'--------------------------------------
hWnd = Me.Text1.hWnd
hDC = GetWindowDC(hWnd)
' hDC = GetDC(hWnd) '<Alternative
'--------------------------------------------------------
'Install the New Font Information on the Device
'--------------------------------------------------------
Call fCreateFontIndirect(hDC, strFontName, lngFontSize) 'My Simplied Test Function
'------------------------------------------
'Assign the New Font to the Control
'------------------------------------------
Me.Text1.Font.Name = strFontName
Me.Text1.Font.Size = lngFontSize
'********
'MAIN
'********
'-----------------------
'Get Font Part Details of the Newly Assigned Font
'------------------------
GetTextMetrics hDC, mymetrics
InternalLeading = mymetrics.tmInternalLeading
Ascent = mymetrics.tmAscent
Descent = mymetrics.tmDescent
ExternalLeading = mymetrics.tmExternalLeading
'-----------------------------------------
'Calc the Font Height from Its Parts
'----------------------------------------
iHeight = Ascent + Descent - InternalLeading
'---------------------------------------------
'Verify the Height (in Pixels) is Correct
'---------------------------------------------
VerifyHeightPixels = ScaleY(Me.Text1.FontSize, vbPoints, vbPixels)
'-----------------------------------
'Verify the Font Size is Correct
'-----------------------------------
VerifyFSizePoints = ScaleY(iHeight, vbPixels, vbPoints)
'********
'WRAPUP
'********
Call ReleaseDC(hWnd, hDC)
End Sub
Private Sub fCreateFontIndirect(hDC As Long, strFontName As String, lngFontSize As Long)
'Modified From: 'URL: http://www.allapi.net/
Dim ThisFont As LOGFONT
Dim rFont As Variant
'Set the height of the font
ThisFont.lfHeight = (lngFontSize * -20) / Screen.TwipsPerPixelY '<< WHAT"S THE -20
'Create the font
rFont = CreateFontIndirect(ThisFont)
If IsNull(rFont) Then
MsgBox "fCreateFontIndirect Failed"
End If
'Select the font into the Controls device context
Call SelectObject(hDC, rFont)
End Sub