1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35
| Function truncator(Ctrl As Control, ctrl2 As Control) As String
Dim X As Long
Dim Xsusp As Long
Dim y As Long
Dim cch As Long
Dim lmax As Long
Dim sTexte As String
Dim iNbreCar As Integer
Dim i As Integer
sTexte = Ctrl.Value
iNbreCar = Len(Ctrl.Value)
WizHook.Key = 51488399
WizHook.TwipsFromFont Ctrl.FontName, Ctrl.FontSize, Ctrl.FontWeight, Ctrl.FontItalic, Ctrl.FontUnderline, cch, sTexte, lmax, X, y
' controle trop court on rajoute les points de suspension
If ctrl2.Width < X Then
WizHook.TwipsFromFont Ctrl.FontName, Ctrl.FontSize, Ctrl.FontWeight, Ctrl.FontItalic, Ctrl.FontUnderline, cch, "...", lmax, Xsusp, y
End If
' on enlève un caractère à droite jusqu'à ce que ça rentre (avec les points de suspension)
Do While X + Xsusp > ctrl2.Width
iNbreCar = iNbreCar - 1
sTexte = Left(sTexte, iNbreCar)
WizHook.TwipsFromFont Ctrl.FontName, Ctrl.FontSize, Ctrl.FontWeight, Ctrl.FontItalic, Ctrl.FontUnderline, cch, Left(sTexte, iNbreCar), lmax, X, y
Debug.Print sTexte, ctrl2.Width, X, Xsusp
Loop
If Xsusp > 0 Then
truncator = Left(Ctrl.Value, iNbreCar) & "..."
Else
truncator = Left(Ctrl.Value, iNbreCar)
End If
End Function |
Partager