Members

Technology Zones

Articles

Hosted By

MaximumASP

Info

Rated
Read 12,577 times

Related Categories

Fit Filenames Into a Specified Width

Kimmy

You will need: Command1 and Label1.

' In general declarations
Private Declare Function PathCompactPath Lib "shlwapi" Alias "PathCompactPathA" (ByVal hDC As Long, ByVal lpszPath As String, ByVal dx As Long) As Long

' On a  Form
Private Sub Command1_Click()
   Dim lhDC As Long, lCtlWidth As Long
   Dim FileSpec As String
   
   FileSpec = "C:\MyFolder\VisualBasic\MyReallyWayTooLongFolderName\ButWhoCares\IhaveTheAPI.doc"
   
   Me.ScaleMode = vbPixels
   
   lCtlWidth = Label1.Width - Me.DrawWidth
   lhDC = Me.hDC
   
   PathCompactPath lhDC, FileSpec, lCtlWidth
   
   Label1.Caption = FileSpec
End Sub

Click the button and see that the FileSpec variable is shortened to fit inside the label1's width.

Till the Roof comes off Till the Lights go out Till my Legs give out Can't shut my mouth I will not fall, my Wisdoms all.

Comments