Public Class MyCheckedListBox
Inherits CheckedListBox
Private Const WM_LBUTTONDOWN As Integer = &H201
Private Const WM_LBUTTONUP As Integer = &H202
Private Const WM_LBUTTONDBLCLK As Integer = &H203
Protected Overrides Sub WndProc(ByRef m As System.Windows.Forms.Message)
Select Case m.Msg
Case WM_LBUTTONDOWN, WM_LBUTTONUP, WM_LBUTTONDBLCLK
Dim pt As Point = Me.PointToClient(Cursor.Position)
For i As Integer = Me.TopIndex To Me.Items.Count - 1
If Me.GetItemRectangle(i).Contains(pt) Then
MyBase.WndProc(m)
Exit Sub
End If
Next
Exit Sub ' Left click occurred in the white space: suppress default action
End Select
MyBase.WndProc(m)
End Sub
End Class
|