Redimensionner un combo en fonction du contenu

sonoboss Messages postés 178 Date d'inscription lundi 17 juin 2002 Statut Membre Dernière intervention 2 octobre 2007 - 9 janv. 2003 à 11:51
cs_MyC Messages postés 94 Date d'inscription lundi 23 septembre 2002 Statut Membre Dernière intervention 22 avril 2003 - 26 mars 2003 à 09:20
Voila mon pb je doit faire un prog en un minimum d'espace et donc pour optimiser je regroupe au max...

Je me retrouve donc avec plusieur contenu de taille différentes ds mon combobox et le combo est trop petit...

Ya til un moyen pour adapter dynamiqement la taille d'un combo par rapport à son contenu???

Merci d'avance!

Le jour où la merde vaudra de l'or, les pauvres naîtons sans trou du cul!

4 réponses

BasicInstinct Messages postés 1470 Date d'inscription mardi 5 février 2002 Statut Membre Dernière intervention 20 octobre 2014 12
9 janv. 2003 à 12:16
faut voir avec me.textwidth & l'api sendmessage

:clown) BasicInstinct :clown)
0
sonoboss Messages postés 178 Date d'inscription lundi 17 juin 2002 Statut Membre Dernière intervention 2 octobre 2007
9 janv. 2003 à 12:52
Tu pourrais développer parce que là tu l'avance pas des masses...

Le jour où la merde vaudra de l'or, les pauvres naîtons sans trou du cul!
0
cs_MyC Messages postés 94 Date d'inscription lundi 23 septembre 2002 Statut Membre Dernière intervention 22 avril 2003
9 janv. 2003 à 13:53
Salut sonoboss !

Voilà la solution :

Option Explicit

Private Declare Function MoveWindow& Lib "user32" (ByVal hwnd As Long, _
ByVal x As Long, ByVal y As Long, ByVal nWidth As Long, _
ByVal nHeight As Long, ByVal bRepaint As Long)

Private Sub Combo1_DropDown()
SetDropdownHeight Combo1, ScaleHeight
End Sub

' Adjust height of combobox dropdown part; call in response to DropDown event
Private Sub SetDropdownHeight(cbo As ComboBox, ByVal max_extent As Integer)
' max_extent is the absolute maximum clientY value that the dropdown may extend to
' case 1: nItems <= 8 : do nothing - vb standard behaviour
' case 2: Items will fit in defined max area : resize to fit
' case 3: Items will not fit : resize to defined max height

If cbo.ListCount > 8 Then
Dim max_fit As Integer ' maximum number of items that will fit in maximum extent
Dim item_ht As Integer ' Calculated height of an item in the dropdown

item_ht = ScaleY(cbo.Height, ScaleMode, vbPixels) - 8
max_fit = (max_extent - cbo.Top - cbo.Height) \ ScaleY(item_ht, vbPixels, ScaleMode)

If cbo.ListCount <= max_fit Then
MoveWindow cbo.hwnd, ScaleX(cbo.Left, ScaleMode, vbPixels), _
ScaleY(cbo.Top, ScaleMode, vbPixels), _
ScaleX(cbo.Width, ScaleMode, vbPixels), _
ScaleY(cbo.Height, ScaleMode, vbPixels) + (item_ht * cbo.ListCount) + 2, 0
Else
MoveWindow cbo.hwnd, ScaleX(cbo.Left, ScaleMode, vbPixels), _
ScaleY(cbo.Top, ScaleMode, vbPixels), _
ScaleX(cbo.Width, ScaleMode, vbPixels), _
ScaleY(cbo.Height, ScaleMode, vbPixels) + (item_ht * max_fit) + 2, 0
End If

End If

End Sub

Private Sub Form_Load()
Dim i As Integer

For i = 0 To 10
Combo1.AddItem "Item " & i
Next i

End Sub

J'espère que ça va t'aider. A plus !
0
cs_MyC Messages postés 94 Date d'inscription lundi 23 septembre 2002 Statut Membre Dernière intervention 22 avril 2003
26 mars 2003 à 09:20
Si qqun à une idée pour les imageBox, car ce code ne fonctionne que pour les comboBox !
0
Rejoignez-nous