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 Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

String wide in pixels 1

Status
Not open for further replies.

jamsek19

Programmer
Feb 4, 2002
35
SI
Hello.
Can anyone tell me, how to determine string wide in pixels or twips. For example Label1.Caption width in pixels.
Thanks in advance
Andrej
 
I think this is what you are looking for

Dim lWidth As Single
lWidth = label1.width
 
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
 
Hello. Thanks all of you for reply.

The function from STRONGM works just in run time.

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.

How can I do that.
Thanks
Andrej
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top