Try the following: [tt]
' Returns width of caption for given label, optionally in selected units (default is pixels)
Public Function GetWidthLabelText(lblSource As Label, Optional ScaleMode As ScaleModeConstants = vbPixels) As Long
Dim OldParentFont As Font
Dim OldScaleMode As ScaleModeConstants
With lblSource.Parent
Set OldParentFont = .Font
Set .Font = lblSource.Font
OldScaleMode = .ScaleMode
.ScaleMode = ScaleMode
GetWidthLabelText = .TextWidth(lblSource.Caption)
Set .Font = OldParentFont
.ScaleMode = OldScaleMode
End With
End Function
I want to make ActiveX control, which use Labels and TextBoxes. Therefore I need to calculate label caption width at designing time.
Example:
I put my control into form. When I set caption of my control, which is acctualy label caption, I want to move all TextBoxes in my control to the right of the longest label's caption. This must depends on label's font too.
This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
By continuing to use this site, you are consenting to our use of cookies.