如何改变ComboBox列表框下拉部分的高度???

wangrun2000 2001-03-22 06:20:00
今日又编程,又遇到问题,苦熬一夜,不得结果,特请教各位大虾!
如何改变ComboBox列表框下拉部分的高度???
在VB里,这个高度的默认值是8
我已知道如何增大它!
但不知如何减小它!!!!
特请教!
...全文
365 16 打赏 收藏 转发到动态 举报
写回复
用AI写文章
16 条回复
切换为时间正序
请发表友善的回复…
发表回复
lchang001 2001-04-10
  • 打赏
  • 举报
回复
好像改变COMBOBOX中的文本大小时可以改变它的高度!
小牛 2001-04-10
  • 打赏
  • 举报
回复
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) As Long

Public Function SetComboBoxHeight(objCB As ComboBox, _
TheHeight As Single) As Boolean

'*************************************************

'PURPOSE: Sets dropdown height of combo box
' in Inches
'函数:设置combo下拉框的长度
'SAMPLE USAGE:
' SetComboBoxHeight combo1, 4
'
'RETURNS: True if successful, false otherwise
'
'USAGE NOTES: The Function must be placed in the
' Same Form Module that contains the
' ComboBox
'
' The combo box's parent must be a form
' not a container such as picture box or
' a frame
'
' The scale mode of the form must
' be twips
'
' Only works to increase drop-down
' height, not decrease it
'
' The increase height won't go beyond
' the maximum viewable space of the
' combo box (i.e., there will be
' no padded blank space on the bottom
' of the combo box


'*************************************************

On Error Resume Next
Dim lHeight As Single
lHeight = TheHeight * 1440 'inches to pixels
lHeight = lHeight / Screen.TwipsPerPixelY
Me.ScaleMode = vbPixels
With objCB
MoveWindow .hwnd, .Left, .Top, .Width, lHeight, 1
End With
Me.ScaleMode = vbTwips

SetComboBoxHeight = Err.Number = 0 And Err.LastDllError = 0


End Function
NiceFeather 2001-04-10
  • 打赏
  • 举报
回复
看看这个:
http://www.csdn.net/dev/Visual%20Basic/source%20code/Control%20Examples/combohgt.zip
pgfan 2001-04-10
  • 打赏
  • 举报
回复
Public Sub SetDropHeight(Cbo As Object, numItemsToDisplay As Long)
Dim pt As POINTAPI
Dim rc As RECT
Dim cWidth As Long
Dim newHeight As Long
Dim oldScaleMode As Long

Dim itemHeight As Long

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

'the width of the combo, used below
cWidth = Cbo.Width
'get the system height of a single combo box list item
itemHeight = SendMessage(Cbo.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(Cbo.hwnd, rc)
pt.x = rc.Left
pt.Y = rc.Top
'Then translate into co-ordinates relative to the form.
Call ScreenToClient(frmMain.hwnd, pt)
'Using the values returned and set above,
'call MoveWindow to reposition the combo box
Call MoveWindow(Cbo.hwnd, pt.x, pt.Y, Cbo.Width, newHeight, True)
'Its done, so show the new combo height
'Call SendMessage(Combo1.hwnd, CB_SHOWDROPDOWN, True, ByVal 0)

'restore the original form scalemode before leaving
frmMain.ScaleMode = oldScaleMode
End Sub
QQRN 2001-04-10
  • 打赏
  • 举报
回复
TO Arcan(Arcan)
真的可以吗?
binghuodao 2001-04-10
  • 打赏
  • 举报
回复
Arcan 2001-04-09
  • 打赏
  • 举报
回复
这个问题呀,只要改变combo控件的font属性就行了,把字体的字号改变就行了,去试试。呵呵。
wangrun2000 2001-03-24
  • 打赏
  • 举报
回复
newguo(new):
你好,你能不能把自编控件的过程说一下??!!
谢了!!
wangrun2000 2001-03-24
  • 打赏
  • 举报
回复
kkk
wangrun2000 2001-03-24
  • 打赏
  • 举报
回复
neweguo(new):
你好!
请问请教哪位老外?或到哪个网站请教??
自编控件可以吗??怎么做??说具体点!!
减小高度值可以节约界面空间,不能说无所谓,有scroll我当然知道,可它能减小高度值吗?!!
大雄 2001-03-23
  • 打赏
  • 举报
回复
我只知道在Access97中的ComboBox可以随意设置高度值,如果能把它借来用就好了。
wangrun2000 2001-03-23
  • 打赏
  • 举报
回复
new,Arcan :
你们好!
小牛 2001-03-23
  • 打赏
  • 举报
回复
看来只有求教老外,或者自编控件了。不过高度值也无所谓啊,有scroll就成了
wangrun2000 2001-03-23
  • 打赏
  • 举报
回复
大雄:
你好,不错的,给点分!!
Arcan 2001-03-22
  • 打赏
  • 举报
回复
下拉部分的高度?我也想知道怎么办
小牛 2001-03-22
  • 打赏
  • 举报
回复
关注!

7,787

社区成员

发帖
与我相关
我的任务
社区描述
VB 基础类
社区管理员
  • VB基础类社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧