Combo 预设的下拉长度只有 5,6 个选项,当选项很多时,要卷老半天才能找到资料,很不方便!要加长 ComboBox 的下拉选单,方法如下:
在声明区中放入以下声明及 Subroutine
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
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
在任何时候 (不一定是 Form_Load 或 Combo_DropDown),想要加长 ComboBox 的下拉选单时,只要加入以下程序即可:
Call SetComboHeight(Combo1, 270) '设定的单位是 Pixels
至少要成为本站的注册会员才能下载! 注册点我!
|