|
Добавление элемента CheckBox в элемент ComboBox |
|
|
Данный пример покажет, как можно вставить элемент CheckBox внутрь элемента ComboBox. Добавьте на форму 1 ComboBox и 1 CheckBox. Private Const EC_LEFTMARGIN = &H1
Private Const EC_RIGHTMARGIN = &H2
Private Const EC_USEFONTINFO = &HFFFF&
Private Const EM_SETMARGINS = &HD3&
Private Const EM_GETMARGINS = &HD4&
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
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()
AddCheckToCombo Check1, Combo1
Dim i As Long
For i = 1 To 20
Combo1.AddItem "Test" & i
Next i
End Sub
|
|
|
|
|
|
|