get-width-of-string

 

Get The Width Of A String


Get The Width Of A String


Preparations

Add 1 Label to your form (named Label1).
Set the Label AutoSize propery to True, and Visible propery to False


Form Code

Private Function TextExtent(txt As String) As Integer
Label1.Caption = txt
TextExtent = Label1.Width
End Function

Private Sub Form_Load()
'change the "VBTown" below with the string you want to measure
MsgBox ("The width of the string 'VBTown' is: " &
TextExtent("VBTown"))
End Sub