Option ExplicitPrivate 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_GETITEMHEIGHT = &H1A1 Private Const LB_SETITEMHEIGHT = &H1A0 Dim lstH As LongPrivate Sub Command1_Click() lstH = SendMessage(List1.hwnd, LB_GETITEMHEIGHT, 0, ByVal 0&) MsgBox "列表框条目原来的高度是:" & lstH, , "" Command2.Enabled = True Command3.Enabled = True Command4.Enabled = True End SubPrivate Sub Command2_Click() Dim temp As Single Dim lstHtemp As Long temp = InputBox("请输入列表框条目的新的高度(原来高度的倍数)") lstHtemp = CLng(temp * lstH) SendMessage List1.hwnd, LB_SETITEMHEIGHT, 0, ByVal lstHtemp List1.Refresh MsgBox "列表框条目的新高度势:" & lstHtemp, , "" End SubPrivate Sub Command3_Click() SendMessage List1.hwnd, LB_SETITEMHEIGHT, 0, ByVal lstH List1.Refresh End SubPrivate Sub Command4_Click() Unload Me End SubPrivate Sub Form_Load() List1.AddItem "AAAAAAAAAA" List1.AddItem "BBBBBBBBBBBBBB" List1.AddItem "CCCCCCCCCCCCCCCCCCCC" List1.AddItem "DDDDDDDDDDDDD"
设置列表项的高度: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 Const LB_SETITEMHEIGHT = &H1A0 Const CB_SETITEMHEIGHT = &H153' Set the height in pixels of each entry in a ListBox or ComboBox controlSub SetListItemHeight(ctrl As Control, ByVal newHeight As Long) Dim uMsg As Long If TypeOf ctrl Is ListBox Then 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. ctrl.Refresh End Sub
用TREEVIEW行不?
Private Const LB_GETITEMHEIGHT = &H1A1
Private Const LB_SETITEMHEIGHT = &H1A0
Dim lstH As LongPrivate Sub Command1_Click()
lstH = SendMessage(List1.hwnd, LB_GETITEMHEIGHT, 0, ByVal 0&)
MsgBox "列表框条目原来的高度是:" & lstH, , ""
Command2.Enabled = True
Command3.Enabled = True
Command4.Enabled = True
End SubPrivate Sub Command2_Click()
Dim temp As Single
Dim lstHtemp As Long
temp = InputBox("请输入列表框条目的新的高度(原来高度的倍数)")
lstHtemp = CLng(temp * lstH)
SendMessage List1.hwnd, LB_SETITEMHEIGHT, 0, ByVal lstHtemp
List1.Refresh
MsgBox "列表框条目的新高度势:" & lstHtemp, , ""
End SubPrivate Sub Command3_Click()
SendMessage List1.hwnd, LB_SETITEMHEIGHT, 0, ByVal lstH
List1.Refresh
End SubPrivate Sub Command4_Click()
Unload Me
End SubPrivate Sub Form_Load()
List1.AddItem "AAAAAAAAAA"
List1.AddItem "BBBBBBBBBBBBBB"
List1.AddItem "CCCCCCCCCCCCCCCCCCCC"
List1.AddItem "DDDDDDDDDDDDD"
Command1.Caption = "显示原高度"
Command2.Caption = "设置新高度"
Command3.Caption = "恢复原高度"
Command4.Caption = "退 出"
Form1.Caption = "用列表框消息设置条目高度"
Command2.Enabled = False
Command3.Enabled = False
Command4.Enabled = False
End Sub'四个按钮,一个列表框
hwnd As Long, ByVal wMsg As Long, ByVal wParam As Long, _
lParam As Any) As Long
Const LB_SETITEMHEIGHT = &H1A0
Const CB_SETITEMHEIGHT = &H153' Set the height in pixels of each entry in a ListBox or ComboBox controlSub SetListItemHeight(ctrl As Control, ByVal newHeight As Long)
Dim uMsg As Long
If TypeOf ctrl Is ListBox Then
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.
ctrl.Refresh
End Sub
双击工具箱中的 ListBox 就行了。或者但是工具箱中的 ListBox ,然后用鼠标在窗体上画一个。
从API View中复制啊