首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 开发语言 > VB >

怎么调节list 每个项目之间的 间距

2012-01-23 
如何调节list 每个项目之间的 间距?如题...[解决办法]Option ExplicitPrivate Declare Function SendMessa

如何调节list 每个项目之间的 间距?
如题     ...

[解决办法]
Option Explicit

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 Const LB_SETITEMHEIGHT = &H1A0
Private Const CB_SETITEMHEIGHT = &H153


Private Declare Function ShowScrollBar Lib "user32 " (ByVal hwnd As Long, _
ByVal wBar As Long, ByVal bShow As Long) As Long

Private Const SB_BOTH = 3
Private Const SB_CTL = 2
Private Const SB_HORZ = 0
Private Const SB_VERT = 1


' Set the height in pixels of each entry in a ListBox or ComboBox control
Sub SetListItemHeight(ctrl As Control, ByVal newHeight As Long)
Dim uMsg As Long
If TypeOf ctrl Is ListBox Then 'newHeight²»¿ÉÒÔ´óÓÚ255
uMsg = LB_SETITEMHEIGHT
ElseIf TypeOf ctrl Is ComboBox Then
uMsg = CB_SETITEMHEIGHT
Else
Exit Sub
End If
' (only the low-order word of lParam can be used.)
SendMessage ctrl.hwnd, uMsg, 0, ByVal CLng(newHeight And &HFFFF&)
' It is necessary to manually refresh the control.
If TypeOf ctrl Is ListBox Then ShowScrollBar ctrl.hwnd, SB_VERT, True

ctrl.Refresh
End Sub

Private Sub Command1_Click()
SetListItemHeight List1, 20
SetListItemHeight Combo1, 20
End Sub

Private Sub Form_Load()
Dim i As Integer
For i = 1 To 9
List1.AddItem CStr(i)
Combo1.AddItem CStr(i)
Next
End Sub

热点排行