Returns the height and width in pixels of a string based on the current font characteristics of a d
Returns the height and width in pixels of a string based on the current font characteristics of a device context (DC) using the
API Declarations
Private Declare Function GetTextExtentPoint32 Lib "gdi32" Alias "GetTextExtentPoint32A" (ByVal hdc As Long, ByVal lpsz As String, ByVal cbString As Long, lpSize As Size) As Long
Private Type Size
cx As Long
cy As Long
End Type
Rate Returns the height and width in pixels of a string based on the current font characteristics of a d
(1(1 Vote))
Dim szText As Size
Dim iStrLen As Long
Dim strText As String
Dim lRet As Long
strText = "HELLO WORLD"
iStrLen = Len(strText) ' retrieve the number of characters in the string
lRet = GetTextExtentPoint32(Picture1.hdc, strText, iStrLen, szText) ' retrieve the height and width of the string
If Not lRet = 0 Then
'if function call was successful then display the dimensions of the string based on the current font of _
the picture, to test this try changing the font characteristics of the Picture box and run this function _
again
Label1.Caption = "The string " & strText & " is " & _
szText.cx & " pixels wide and " & _
szText.cy & " pixels high!"
Else
' if the function call failed alert the user via the label
Label1.Caption = "API CALL DID NOT FUNCTION PROPERLY!!"
End If
End Sub
Returns the height and width in pixels of a string based on the current font characteristics of a d Comments
No comments yet — be the first to post one!
Post a Comment