请问:怎样才能控制listbox中Item的高度呢?如何实现?

解决方案 »

  1.   

    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' 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
      

  2.   

    你要调用这个函数啊 
    晕死
    SetListItemHeight 你要改变的句柄,你要的高度
      

  3.   

    SetListItemHeight List1, 1000
    这样是吗,我做了,但是不起作用呀
      

  4.   

    刚试过的代码,有效:(在form 上放一个 list1,一个 command1)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_SETITEMHEIGHT = &H1A0
    Private 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 SubPrivate Sub Command1_Click()
        SetListItemHeight List1, 20
    End SubPrivate Sub Form_Load()
        Dim i As Integer
        For i = 1 To 9
            List1.AddItem CStr(i)
        Next
    End Sub
      

  5.   

    如果原来的list没有滚动条,这样改变每列的高度后不会自动出现滚动条,我想最好把ctrl.Refresh该为 ShowScrollBar ctrl.hwnd, SB_VERT, True,这样就会添加滚动条,并且ShowScrollBar会包含有刷新的过程。
      

  6.   

    呵呵,在原来就有滚动条的时候ctrl.Refresh还是要的,我想可能是因为ShowScrollBar函数会先检测是不是已经有了滚动条吧。