Library code snippets

Fit Filenames Into a Specified Width

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.

Comments

  1. 17 Nov 2002 at 08:13

    You're too damm clever...............very good

  2. 01 Jan 1999 at 00:00

    This thread is for discussions of Fit Filenames Into a Specified Width.

Leave a comment

Sign in or Join us (it's free).

Kym Manson 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.

Related discussion

Related podcasts

  • Christian Beauclair

    14 mai 2008 (�mission #0074) ::.Christian Beauclair: Stratégies de migration VB6 vers .NET Nous discutons avec Christian Beauclair des stratégies de migration VB6 vers .NET. Entre autres, nous discutons comment utiliser le "VB 6 Code Advisor" et le "Interop Forms Toolkit" pour ajouter la puiss...

We'd love to hear what you think! Submit ideas or give us feedback