How to add CheckBox to ComboBox
Posted on January 5, 2009
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 | 'Controls - How to add CheckBox to ComboBox Option Explicit 'Add a Combo Box and a Check Box to your form and set CheckBox width property and height property to 130. 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 Public Const EC_LEFTMARGIN = &H1 Public Const EC_RIGHTMARGIN = &H2 Public Const EC_USEFONTINFO = &HFFFF& Public Const EM_SETMARGINS = &HD3& Public Const EM_GETMARGINS = &HD4& Private Sub AddCheckToCombo(ByRef chkThis As CheckBox, ByRef cboThis As ComboBox) Dim lhWnd As Long, 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 chkThis.ZOrder End If End Sub 'How can I call this routine: Private Sub Form_Load() AddCheckToCombo Check1, Combo1 End Sub |