Make your own free website on

Add CheckBox To ComboBox

'Add a module to your project (In the menu choose Project -> Add Module, Then click Open)
'Add 1 Combo Box and 1 Check Box to your form.
'Set CheckBox Width property and Height property to 130.
'Insert this code to the module :

Public Const EC_LEFTMARGIN = &H1
Public Const EC_RIGHTMARGIN = &H2
Public Const EM_SETMARGINS = &HD3&
Public Const EM_GETMARGINS = &HD4&
Declare Function FindWindowEx Lib "user32" Alias "FindWindowExA" _
(ByVal hwndParent As Long, ByVal hwndChildAfter As Long, ByVal lpszClass As String, _
ByVal lpszWindow As String) As Long
Declare Function SendMessageLong Lib "user32" Alias "SendMessageA" _
(ByVal hwnd As Long, ByVal wMsg As Long, ByVal wParam As Long, ByVal lParam As Long) As Long

'Insert the following code to your form:

Private Sub AddCheckToCombo(ByRef chkThis As CheckBox, ByRef cboThis As ComboBox)
Dim lhWnd As Long
Dim lMargin As Long
lhWnd = FindWindowEx(cboThis.hwnd, 0, "EDIT", vbNullString)
If (lhWnd <> 0) Then
lMargin = chkThis.Width \ Screen.TwipsPerPixelX + 2
SendMessageLong lhWnd, EM_SETMARGINS, EC_LEFTMARGIN, lMargin
chkThis.BackColor = cboThis.BackColor
chkThis.Move cboThis.Left + 3 * Screen.TwipsPerPixelX, cboThis.Top + 2 * Screen.TwipsPerPixelY, chkThis.Width, cboThis.Height - 4 * Screen.TwipsPerPixelY
End If
End Sub

Private Sub Form_Load()
AddCheckToCombo Check1, Combo1
End Sub

Go Back