OVH Cloud OVH Cloud

Nombre d'élément visible dans une ComboxBox

3 réponses
Avatar
Daniel AUBRY
Bonjour à tous,

comme dit dans le titre, je cherche à paramétrer le
nombre déléments visivles dans une liste déroulante.
En fait je cherche surtout à l'agrandir.

Si quelqu'un a une piste.........

D'avance, merci.

Dany

3 réponses

Avatar
X
Bonjour, je crois que c'est le système qui détermine la taille, voir
sir les API (mais on sort de VB), peuvent modifier ça? Sinon, prendre une
listBox...

--
Site logiciels
http://irolog.free.fr
Mail
http://irolog.free.fr/ecrire/index.htm
Site perso
http://irolog.free.fr/joe/index.htm
Principe d'utilisation des news Groups
http://support.microsoft.com/directory/worldwide/fr/newsgroup/regles.htm
------------------------------------------------------------------------------------
"Daniel AUBRY" a écrit dans le message de news:
44ed90db$0$1730$
Bonjour à tous,

comme dit dans le titre, je cherche à paramétrer le
nombre déléments visivles dans une liste déroulante.
En fait je cherche surtout à l'agrandir.

Si quelqu'un a une piste.........

D'avance, merci.

Dany



Avatar
Driss HANIB
Trouvé dans un prog français, reprenant lui même des données sur mvps.org

'http://vbnet.mvps.org/index.html?code/comboapi/comboheight.htm

'The Visual Basic combo box dropdown - unlike its C counterpart -
'is limited to displaying only eight items.
'This page shows how to change the dropdown height to any number greater
than eight.


Private Const CB_SHOWDROPDOWN = &H14F
Private Const CB_GETITEMHEIGHT = &H154

Private Type POINTAPI
X As Long
Y As Long
End Type

Private Type RECT
Left As Long
Top As Long
Right As Long
Bottom As Long
End Type

Private Declare Function SendMessage Lib "user32" _
Alias "SendMessageA" _
(ByVal hwnd As Long, _
ByVal wMsg As Long, _
ByVal wParam As Long, _
lParam As Any) As Long

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) As Long

Private Declare Function GetWindowRect Lib "user32" _
(ByVal hwnd As Long, _
lpRect As RECT) As Long

Private Declare Function ScreenToClient Lib "user32" _
(ByVal hwnd As Long, _
lpPoint As POINTAPI) As Long



Private Sub Command1_Click()

Dim pt As POINTAPI
Dim rc As RECT
Dim cwidth As Long
Dim newHeight As Long
Dim oldScaleMode As Long
Dim numItemsToDisplay As Long
Dim itemHeight As Long

'how many items should appear in the dropdown?
numItemsToDisplay = 16
Label1.Caption = "Items displayed = " & numItemsToDisplay

'Save the current form scalemode, then
'switch to pixels
oldScaleMode = Form09.ScaleMode
Form09.ScaleMode = vbPixels

'the width of the combo, used below
cwidth = Combo1.Width

'get the system height of a single
'combo box list item
itemHeight = SendMessage(Combo1.hwnd, CB_GETITEMHEIGHT, 0, ByVal 0)

'Calculate the new height of the combo box. This
'is the number of items times the item height
'plus two. The 'plus two' is required to allow
'the calculations to take into account the size
'of the edit portion of the combo as it relates
'to item height. In other words, even if the
'combo is only 21 px high (315 twips), if the
'item height is 13 px per item (as it is with
'small fonts), we need to use two items to
'achieve this height.
newHeight = itemHeight * (numItemsToDisplay + 2)

'get the co-ordinates of the combo box
'relative to the screen
Call GetWindowRect(Combo1.hwnd, rc)
pt.X = rc.Left
pt.Y = rc.Top

'then translate into co-ordinates
'relative to the form.
Call ScreenToClient(Form09.hwnd, pt)

'using the values returned and set above,
'call MoveWindow to reposition the combo box
Call MoveWindow(Combo1.hwnd, pt.X, pt.Y, Combo1.Width, newHeight, True)

'it's done, so show the new combo height
Call SendMessage(Combo1.hwnd, CB_SHOWDROPDOWN, True, ByVal 0)

'restore the original form scalemode
'before leaving
Form09.ScaleMode = oldScaleMode

End Sub

"Daniel AUBRY" a écrit dans le message de
news:44ed90db$0$1730$
Bonjour à tous,

comme dit dans le titre, je cherche à paramétrer le
nombre déléments visivles dans une liste déroulante.
En fait je cherche surtout à l'agrandir.

Si quelqu'un a une piste.........

D'avance, merci.

Dany




Avatar
Daniel AUBRY
Impeccable, exactement ce dont j'ai besoin.
Grand merci.

Dany

"Driss HANIB" a écrit dans le message de news:

Trouvé dans un prog français, reprenant lui même des données sur mvps.org

'http://vbnet.mvps.org/index.html?code/comboapi/comboheight.htm

'The Visual Basic combo box dropdown - unlike its C counterpart -
'is limited to displaying only eight items.
'This page shows how to change the dropdown height to any number greater
than eight.


Private Const CB_SHOWDROPDOWN = &H14F
Private Const CB_GETITEMHEIGHT = &H154

Private Type POINTAPI
X As Long
Y As Long
End Type

Private Type RECT
Left As Long
Top As Long
Right As Long
Bottom As Long
End Type

Private Declare Function SendMessage Lib "user32" _
Alias "SendMessageA" _
(ByVal hwnd As Long, _
ByVal wMsg As Long, _
ByVal wParam As Long, _
lParam As Any) As Long

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) As Long

Private Declare Function GetWindowRect Lib "user32" _
(ByVal hwnd As Long, _
lpRect As RECT) As Long

Private Declare Function ScreenToClient Lib "user32" _
(ByVal hwnd As Long, _
lpPoint As POINTAPI) As Long



Private Sub Command1_Click()

Dim pt As POINTAPI
Dim rc As RECT
Dim cwidth As Long
Dim newHeight As Long
Dim oldScaleMode As Long
Dim numItemsToDisplay As Long
Dim itemHeight As Long

'how many items should appear in the dropdown?
numItemsToDisplay = 16
Label1.Caption = "Items displayed = " & numItemsToDisplay

'Save the current form scalemode, then
'switch to pixels
oldScaleMode = Form09.ScaleMode
Form09.ScaleMode = vbPixels

'the width of the combo, used below
cwidth = Combo1.Width

'get the system height of a single
'combo box list item
itemHeight = SendMessage(Combo1.hwnd, CB_GETITEMHEIGHT, 0, ByVal 0)

'Calculate the new height of the combo box. This
'is the number of items times the item height
'plus two. The 'plus two' is required to allow
'the calculations to take into account the size
'of the edit portion of the combo as it relates
'to item height. In other words, even if the
'combo is only 21 px high (315 twips), if the
'item height is 13 px per item (as it is with
'small fonts), we need to use two items to
'achieve this height.
newHeight = itemHeight * (numItemsToDisplay + 2)

'get the co-ordinates of the combo box
'relative to the screen
Call GetWindowRect(Combo1.hwnd, rc)
pt.X = rc.Left
pt.Y = rc.Top

'then translate into co-ordinates
'relative to the form.
Call ScreenToClient(Form09.hwnd, pt)

'using the values returned and set above,
'call MoveWindow to reposition the combo box
Call MoveWindow(Combo1.hwnd, pt.X, pt.Y, Combo1.Width, newHeight, True)

'it's done, so show the new combo height
Call SendMessage(Combo1.hwnd, CB_SHOWDROPDOWN, True, ByVal 0)

'restore the original form scalemode
'before leaving
Form09.ScaleMode = oldScaleMode

End Sub

"Daniel AUBRY" a écrit dans le message de
news:44ed90db$0$1730$
Bonjour à tous,

comme dit dans le titre, je cherche à paramétrer le
nombre déléments visivles dans une liste déroulante.
En fait je cherche surtout à l'agrandir.

Si quelqu'un a une piste.........

D'avance, merci.

Dany