AllAPI Network - The KPD-Team

 
Allapi Network
 API-Guide
 ApiViewer

 API List

 
API Resources
 Tips & Tricks
 VB Tutorials
 Error Lookup
 
Misc Stuff
 VB examples
 VB Tools
 VB Links
 Top Downloads
 
This Site
 Search Engine
 Contact Form
 

Donate to AllAPI.net

Set the dropdown height of a combobox

This sub uses the MoveWindow API to set the height of the dropdown area of a combo box. Use this sub what you like: it does not have to be in the combo's dropdown event.

To use this tip, call the SetComboHeight procuedure with the name of the combo box you wish to edit, and the size in pixels that the dropdown area should be set to.  For Example:

Call SetComboHeight(Combo1, 1450)

Declarations

Paste this into the declarations section of a module:

Public 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

Procedure

Public Sub SetComboHeight(oComboBox As ComboBox, _
lNewHeight As Long)

Dim oldscalemode As Integer

' This procedure does not work with frames: you
' cannot set the ScaleMode to vbPixels, because
' the frame does not have a ScaleMode Property.
' To get round this, you could set the parent control
' to be the form while you run this procedure.

If TypeOf oComboBox.Parent Is Frame Then Exit Sub

' Change the ScaleMode on the parent to Pixels.
oldscalemode = oComboBox.Parent.ScaleMode
oComboBox.Parent.ScaleMode = vbPixels

' Resize the combo box window.
MoveWindow oComboBox.hwnd, oComboBox.Left, _
oComboBox.Top, oComboBox.Width, lNewHeight, 1

' Replace the old ScaleMode
oComboBox.Parent.ScaleMode = oldscalemode
End Sub

 

 


Copyright © 1998-2007, The Mentalis.org Team - Privacy statement
Did you find a bug on this page? Tell us!
This site is located at http://allapi.mentalis.org/