用API函数DrawTextEx,并且将最后一个标志位设为DT_PATHELLIPSES,其功能是如字串包含了 \ 字符,就用省略号替换字串内容,使其能在矩形中全部容下。例如,一个很长的路径名可能换成这样显示——c:\windows\...\doc\readme.txt

解决方案 »

  1.   

    Private Sub Form_Load()
        MsgBox GetFileName("c:\myfiles\111\222\3333\4444\myfile.txt")
    End Sub
    Function GetFileName(FileName As String) As String
    'Parses the filename out of a directory string
         
         Dim i As Integer
         
         On Error Resume Next
         
         For i = Len(FileName) To 1 Step -1
           If Mid(FileName, i, 1) = "\" Then
             Exit For
           End If
         Next
         
         GetFileName = Mid(FileName, i + 1)End Function