18
Сентябрь
2008
Как добавить CheckBox в ComboBox?
Как добавить CheckBox в ComboBox?
Option Explicit
Private 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
Private 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
Const EC_LEFTMARGIN = &H1
Const EC_RIGHTMARGIN = &H2
Const EC_USEFONTINFO = &HFFFF&
Const EM_SETMARGINS = &HD3&
Const EM_GETMARGINS = &HD4&
Dim i As Byte
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
chkThis.ZOrder
End If
End Sub
Private Sub Form_Load()
Check1.Width = 200
Check1.Height = 200
AddCheckToCombo Check1, Combo1
For i = 0 To 4
Combo1.AddItem i
Next
End Sub
Private Sub Check1_Click()
Label1.Caption = Combo1.ListIndex
End Sub
Private Sub Combo1_Click()
'Если флажок установлен покажем в метке номер строки
If Check1.Value = 1 Then Label1.Caption = Combo1.ListIndex
End Sub