自己做一个这样的控件,用listbox和checkbox控件结合使用

解决方案 »

  1.   

    listbox.height就是行高是整个控件的高度,我想得到item的高度
      

  2.   

    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 = &H1A1Private Sub Command1_Click()
        Msgbox SendMessage(List1.hwnd, LB_GETITEMHEIGHT, 0, 0)
    End Function
      

  3.   

    Option ExplicitPrivate Declare Function GetWindowRect Lib "user32" (ByVal hwnd As Long, lpRect As RECT) As Long
    Private Declare Function GetCursorPos Lib "user32" (lpPoint As POINTAPI) As LongPrivate Type POINTAPI
            x As Long
            y As Long
    End TypePrivate Type RECT
            Left As Long
            Top As Long
            Right As Long
            Bottom As Long
    End TypePrivate Sub Form_Load()
        Dim i As Long
        For i = 1 To 10
            List1.AddItem "Item" & i
        Next i
    End SubPrivate Sub List1_ItemCheck(Item As Integer)
        Dim pt As POINTAPI
        Dim rc As RECT
        
        GetWindowRect List1.hwnd, rc
        GetCursorPos pt
        
        If pt.x > rc.Left + 15 Then
            List1.Selected(Item) = Not List1.Selected(Item)
        End If
    End Sub
      

  4.   

    更正:Option ExplicitPrivate Declare Function GetWindowRect Lib "user32" (ByVal hwnd As Long, lpRect As RECT) As Long
    Private Declare Function GetCursorPos Lib "user32" (lpPoint As POINTAPI) As Long
    Private Declare Function LockWindowUpdate Lib "user32" (ByVal hwndLock As Long) As LongPrivate Type POINTAPI
            X As Long
            Y As Long
    End TypePrivate Type RECT
            Left As Long
            Top As Long
            Right As Long
            Bottom As Long
    End TypePrivate bMouseDown As BooleanPrivate Sub Form_Load()
        Dim i As Long
        For i = 1 To 10
            List1.AddItem "Item" & i
        Next i
    End SubPrivate Sub List1_ItemCheck(Item As Integer)
        Dim pt As POINTAPI
        Dim rc As RECT
        
        GetWindowRect List1.hwnd, rc
        GetCursorPos pt
        
        If (pt.X > rc.Left + 15) And bMouseDown Then
            bMouseDown = False
            List1.Selected(Item) = Not List1.Selected(Item)
        End If
    End SubPrivate Sub List1_MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single)
        bMouseDown = True
        LockWindowUpdate List1.hwnd
    End SubPrivate Sub List1_MouseUp(Button As Integer, Shift As Integer, X As Single, Y As Single)
        LockWindowUpdate 0
    End Sub