我需要在触摸屏程序中使用LISTBOX控件,默认间距太小,加大字体又太难看,请问在不加大字体的情况下怎么使行间距增大?
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_GETITEMHEIGHT = &H1A1
Private Const LB_SETITEMHEIGHT = &H1A0
Dim lstH As Long
Private Sub Command1_Click()
lstH = SendMessage(List1.hwnd, LB_GETITEMHEIGHT, 0, ByVal 0&)
MsgBox "列表框条目原来的高度是:" & lstH, , ""
Command2.Enabled = True
Command3.Enabled = True
Command4.Enabled = True
End Sub
Private 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 Sub
Private Sub Command3_Click()
SendMessage List1.hwnd, LB_SETITEMHEIGHT, 0, ByVal lstH
List1.Refresh
End Sub
Private Sub Command4_Click()
Unload Me
End Sub
Private 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
四个按钮,一个列表框
设置列表项的高度:
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 control
Sub 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