5/5 (19 avis)
Snippet vu 15 024 fois - Téléchargée 61 fois
'DECLARATION API Declare Function DrawText Lib "user32" Alias "DrawTextA" (ByVal hdc As Long, ByVal lpStr As String, ByVal nCount As Long, lpRect As RECT, ByVal wFormat As Long) As Long Declare Function GetSystemMetrics Lib "user32" _ (ByVal nIndex As Long) As Long Public Declare Function SendMessage Lib _ "user32" Alias "SendMessageA" _ (ByVal hwnd As Long, _ ByVal wMsg As Long, _ ByVal wParam As Long, _ lParam As Any) As Long 'DECLARATION CONSTANTES Public Const LB_GETHORIZONTALEXTENT = &H193 Public Const LB_SETHORIZONTALEXTENT = &H194 ublic Const DT_CALCRECT = &H400 Public Const SM_CXVSCROLL = 2 'DECLARATION TYPE Public Type RECT Left As Long Top As Long Right As Long Bottom As Long End Type Public Sub ApplyScrollBar(fForm As Form, fList As ListBox) Dim c As Long Dim rcText As RECT Dim newWidth As Long Dim itemWidth As Long Dim sysScrollWidth As Long fForm.Font.Name = fList.Font.Name fForm.Font.Bold = fList.Font.Bold fForm.Font.Size = fList.Font.Size sysScrollWidth = GetSystemMetrics(SM_CXVSCROLL) For c = 0 To fList.ListCount - 1 Call DrawText(fForm.hdc, (fList.List(c)), -1&, rcText, DT_CALCRECT) itemWidth = rcText.Right + sysScrollWidth If itemWidth >= newWidth Then newWidth = itemWidth End If Next Call SendMessage(fList.hwnd, LB_SETHORIZONTALEXTENT, newWidth, ByVal 0&) End Sub
16 févr. 2010 à 15:15
En effet c'est mieux comme ca...
16 févr. 2010 à 15:06
16 févr. 2010 à 15:04
chez moi (xp pro) ca ne fonctionne pas, ca me met le message :
Erreur de compilation
Cet argument n'est pas facultatif
A l'instruction :
ApplyScrollBar Me
Me.List1
quelqu'un à une réponse?
j'ai bien une listbox du nom de list1 et j'ai bien copié le code ci-dessus.
Moi rien comprendre... Help!
6 juil. 2008 à 15:54
6 juil. 2008 à 11:01
Vous n'êtes pas encore membre ?
inscrivez-vous, c'est gratuit et ça prend moins d'une minute !
Les membres obtiennent plus de réponses que les utilisateurs anonymes.
Le fait d'être membre vous permet d'avoir un suivi détaillé de vos demandes et codes sources.
Le fait d'être membre vous permet d'avoir des options supplémentaires.