虚拟组合框控件(VirtualCombo)
提供虚拟数据组合框,使用LBS_NODATA样式实现大数据量展示,按需提供数据,支持自绘、增量搜索和OLE拖放。
枚举
VcbStyleConstants
组合框样式常量。
| 常量 | 值 | 说明 |
|---|---|---|
| VcbStyleDropDownCombo | 0 | 下拉组合框(可编辑) |
| VcbStyleSimpleCombo | 1 | 简单组合框 |
| VcbStyleDropDownList | 2 | 下拉列表框(不可编辑) |
VcbDrawModeConstants
绘制模式常量。
| 常量 | 值 | 说明 |
|---|---|---|
| VcbDrawModeNormal | 0 | 标准绘制模式 |
| VcbDrawModeOwnerDrawFixed | 1 | 固定高度自绘模式 |
属性
Name
Public Property Get Name() As String返回在代码中标识对象的名称。
Tag
Public Property Get Tag() As String
Public Property Let Tag(ByVal Value As String)存储程序所需的额外数据。
Parent
Public Property Get Parent() As Object返回对象所在的对象。
Container
Public Property Get Container() As Object
Public Property Set Container(ByVal Value As Object)返回/设置对象的容器。
Left
Public Property Get Left() As Single
Public Property Let Left(ByVal Value As Single)返回/设置对象与其容器左边缘的距离。
Top
Public Property Get Top() As Single
Public Property Let Top(ByVal Value As Single)返回/设置对象与其容器顶边缘的距离。
Width
Public Property Get Width() As Single
Public Property Let Width(ByVal Value As Single)返回/设置对象的宽度。
Height
Public Property Get Height() As Single
Public Property Let Height(ByVal Value As Single)返回/设置对象的高度。
Visible
Public Property Get Visible() As Boolean
Public Property Let Visible(ByVal Value As Boolean)返回/设置对象是否可见。
ToolTipText
Public Property Get ToolTipText() As String
Public Property Let ToolTipText(ByVal Value As String)返回/设置鼠标悬停时显示的提示文本。
HelpContextID
Public Property Get HelpContextID() As Long
Public Property Let HelpContextID(ByVal Value As Long)返回/设置帮助上下文ID。
WhatsThisHelpID
Public Property Get WhatsThisHelpID() As Long
Public Property Let WhatsThisHelpID(ByVal Value As Long)返回/设置关联的上下文帮助ID。
DragIcon
Public Property Get DragIcon() As IPictureDisp
Public Property Let DragIcon(ByVal Value As IPictureDisp)
Public Property Set DragIcon(ByVal Value As IPictureDisp)返回/设置拖放操作中显示的图标。
DragMode
Public Property Get DragMode() As Integer
Public Property Let DragMode(ByVal Value As Integer)返回/设置拖动模式。
hWnd
Public Property Get hWnd() As LongPtr返回控件句柄。
hWndUserControl
Public Property Get hWndUserControl() As LongPtr返回UserControl句柄。
hWndEdit
Public Property Get hWndEdit() As LongPtr返回编辑框句柄。
hWndList
Public Property Get hWndList() As LongPtr返回下拉列表框句柄。
Font
Public Property Get Font() As StdFont
Public Property Let Font(ByVal NewFont As StdFont)
Public Property Set Font(ByVal NewFont As StdFont)返回/设置字体。
VisualStyles
Public Property Get VisualStyles() As Boolean
Public Property Let VisualStyles(ByVal Value As Boolean)返回/设置是否启用视觉样式。需要comctl32.dll 6.0或更高版本。
BackColor
Public Property Get BackColor() As OLE_COLOR
Public Property Let BackColor(ByVal Value As OLE_COLOR)返回/设置背景色。
ForeColor
Public Property Get ForeColor() As OLE_COLOR
Public Property Let ForeColor(ByVal Value As OLE_COLOR)返回/设置前景色。
Enabled
Public Property Get Enabled() As Boolean
Public Property Let Enabled(ByVal Value As Boolean)返回/设置对象是否能响应用户事件。
OLEDragMode
Public Property Get OLEDragMode() As VBRUN.OLEDragConstants
Public Property Let OLEDragMode(ByVal Value As VBRUN.OLEDragConstants)返回/设置OLE拖拽模式。
OLEDropMode
Public Property Get OLEDropMode() As OLEDropModeConstants
Public Property Let OLEDropMode(ByVal Value As OLEDropModeConstants)返回/设置对象是否可以作为OLE放置目标。
MousePointer
Public Property Get MousePointer() As CCMousePointerConstants
Public Property Let MousePointer(ByVal Value As CCMousePointerConstants)返回/设置鼠标悬停时显示的指针类型。参见通用枚举。
MouseIcon
Public Property Get MouseIcon() As IPictureDisp
Public Property Let MouseIcon(ByVal Value As IPictureDisp)
Public Property Set MouseIcon(ByVal Value As IPictureDisp)返回/设置自定义鼠标图标。
MouseTrack
Public Property Get MouseTrack() As Boolean
Public Property Let MouseTrack(ByVal Value As Boolean)返回/设置是否在鼠标进入或离开控件时触发事件。
RightToLeft
Public Property Get RightToLeft() As Boolean
Public Property Let RightToLeft(ByVal Value As Boolean)返回/设置从右到左显示方向。
RightToLeftMode
Public Property Get RightToLeftMode() As CCRightToLeftModeConstants
Public Property Let RightToLeftMode(ByVal Value As CCRightToLeftModeConstants)返回/设置从右到左模式。参见通用枚举。
Style
Public Property Get Style() As VcbStyleConstants
Public Property Let Style(ByVal Value As VcbStyleConstants)返回/设置组合框样式。仅设计时可设置。
Locked
Public Property Get Locked() As Boolean
Public Property Let Locked(ByVal Value As Boolean)返回/设置是否锁定(禁止编辑和选择)。
Text
Public Property Get Text() As String
Public Property Let Text(ByVal Value As String)返回/设置编辑框文本。
Default
Public Property Get Default() As String
Public Property Let Default(ByVal Value As String)返回/设置默认文本。
ExtendedUI
Public Property Get ExtendedUI() As Boolean
Public Property Let ExtendedUI(ByVal Value As Boolean)返回/设置是否使用扩展用户界面(F4键打开下拉列表,ESC键关闭)。
MaxDropDownItems
Public Property Get MaxDropDownItems() As Integer
Public Property Let MaxDropDownItems(ByVal Value As Integer)返回/设置下拉列表最大显示项数。
IntegralHeight
Public Property Get IntegralHeight() As Boolean
Public Property Let IntegralHeight(ByVal Value As Boolean)返回/设置是否调整高度为完整项。仅设计时可设置。
MaxLength
Public Property Get MaxLength() As Long
Public Property Let MaxLength(ByVal Value As Long)返回/设置编辑框最大文本长度。
UseListBackColor
Public Property Get UseListBackColor() As Boolean
Public Property Let UseListBackColor(ByVal Value As Boolean)返回/设置是否使用列表背景色。
UseListForeColor
Public Property Get UseListForeColor() As Boolean
Public Property Let UseListForeColor(ByVal Value As Boolean)返回/设置是否使用列表前景色。
ListBackColor
Public Property Get ListBackColor() As OLE_COLOR
Public Property Let ListBackColor(ByVal Value As OLE_COLOR)返回/设置下拉列表背景色。
ListForeColor
Public Property Get ListForeColor() As OLE_COLOR
Public Property Let ListForeColor(ByVal Value As OLE_COLOR)返回/设置下拉列表前景色。
HorizontalExtent
Public Property Get HorizontalExtent() As Single
Public Property Let HorizontalExtent(ByVal Value As Single)返回/设置下拉列表水平滚动范围。
DrawMode
Public Property Get DrawMode() As VcbDrawModeConstants
Public Property Let DrawMode(ByVal Value As VcbDrawModeConstants)返回/设置绘制模式。仅设计时可设置。
IMEMode
Public Property Get IMEMode() As CCIMEModeConstants
Public Property Let IMEMode(ByVal Value As CCIMEModeConstants)返回/设置输入法模式。参见通用枚举。
ScrollTrack
Public Property Get ScrollTrack() As Boolean
Public Property Let ScrollTrack(ByVal Value As Boolean)返回/设置是否启用滚动跟踪(拖动滑块时实时滚动)。
AutoSelect
Public Property Get AutoSelect() As Boolean
Public Property Let AutoSelect(ByVal Value As Boolean)返回/设置是否自动选择匹配项。
AlwaysFindExact
Public Property Get AlwaysFindExact() As Boolean
Public Property Let AlwaysFindExact(ByVal Value As Boolean)返回/设置是否始终进行精确查找。
ListCount
Public Property Get ListCount() As Long返回列表项数量。
List
Public Property Get List(ByVal Index As Long) As String获取指定索引的列表项文本。通过GetVirtualItem事件获取数据。
ListIndex
Public Property Get ListIndex() As Long
Public Property Let ListIndex(ByVal Value As Long)返回/设置当前选中项索引。
SelStart
Public Property Get SelStart() As Long
Public Property Let SelStart(ByVal Value As Long)返回/设置选择起始位置。
SelLength
Public Property Get SelLength() As Long
Public Property Let SelLength(ByVal Value As Long)返回/设置选择长度。
SelText
Public Property Get SelText() As String
Public Property Let SelText(ByVal Value As String)返回/设置选择的文本。
ItemHeight
Public Property Get ItemHeight() As Single
Public Property Let ItemHeight(ByVal Value As Single)返回/设置项高度。
FieldHeight
Public Property Get FieldHeight() As Single返回编辑框高度。
DroppedDown
Public Property Get DroppedDown() As Boolean
Public Property Let DroppedDown(ByVal Value As Boolean)返回/设置是否处于下拉状态。
DropDownWidth
Public Property Get DropDownWidth() As Single
Public Property Let DropDownWidth(ByVal Value As Single)返回/设置下拉列表宽度。
DropDownHeight
Public Property Get DropDownHeight() As Single
Public Property Let DropDownHeight(ByVal Value As Single)返回/设置下拉列表高度。
TopIndex
Public Property Get TopIndex() As Long
Public Property Let TopIndex(ByVal Value As Long)返回/设置下拉列表顶部可见项索引。
方法
OLEDrag
Public Sub OLEDrag()启动OLE拖放操作。
Drag
Public Sub Drag(Optional ByRef Action As Variant)开始、结束或取消拖动操作。
SetFocus
Public Sub SetFocus()将焦点移到指定对象。
ZOrder
Public Sub ZOrder(Optional ByRef Position As Variant)设置Z顺序。
Refresh
Public Sub Refresh()强制完全重绘对象。
FindItem
Public Function FindItem(ByVal Text As String, Optional ByVal Index As Long = -1, Optional ByVal Partial As Boolean) As Long查找列表项。返回匹配项索引,未找到返回-1。
GetIdealHorizontalExtent
Public Function GetIdealHorizontalExtent() As Single获取理想的水平滚动范围。
SelectItem
Public Function SelectItem(ByVal Text As String, Optional ByVal Index As Long = -1) As Long搜索并选择匹配的列表项。返回选中项索引。
事件
Click
Public Event Click()用户单击控件时触发。
DblClick
Public Event DblClick()用户双击控件时触发。
Scroll
Public Event Scroll()下拉列表滚动时触发。
Change
Public Event Change()文本内容改变时触发。
ContextMenu
Public Event ContextMenu(ByRef Handled As Boolean, ByVal X As Single, ByVal Y As Single)右键上下文菜单事件。设置Handled为True可禁止默认菜单。
GetVirtualItem
Public Event GetVirtualItem(ByVal Item As Long, ByRef Text As String)请求虚拟项数据时触发。需设置Text参数返回项文本。
FindVirtualItem
Public Event FindVirtualItem(ByVal StartIndex As Long, ByVal SearchText As String, ByVal Partial As Boolean, ByRef FoundIndex As Long)搜索虚拟项时触发。需设置FoundIndex返回匹配项索引,未找到设为-1。
IncrementalSearch
Public Event IncrementalSearch(ByVal SearchString As String, ByVal StartIndex As Long, ByRef FoundIndex As Long)增量搜索时触发。需设置FoundIndex返回匹配项索引。
DropDown
Public Event DropDown()下拉列表展开时触发。
CloseUp
Public Event CloseUp()下拉列表关闭时触发。
ItemDraw
Public Event ItemDraw(ByVal Item As Long, ByVal ItemAction As Long, ByVal ItemState As Long, ByVal hDC As Long, ByVal Left As Long, ByVal Top As Long, ByVal Right As Long, ByVal Bottom As Long)自绘项时触发(DrawMode为OwnerDrawFixed时)。
PreviewKeyDown
Public Event PreviewKeyDown(ByVal KeyCode As Integer, ByRef IsInputKey As Boolean)按键预览事件。设置IsInputKey为True可将按键标记为输入键。
PreviewKeyUp
Public Event PreviewKeyUp(ByVal KeyCode As Integer, ByRef IsInputKey As Boolean)按键释放预览事件。
KeyDown
Public Event KeyDown(KeyCode As Integer, Shift As Integer)按下键盘键时触发。
KeyUp
Public Event KeyUp(KeyCode As Integer, Shift As Integer)释放键盘键时触发。
KeyPress
Public Event KeyPress(KeyChar As Integer)按下并释放ANSI键时触发。
MouseDown
Public Event MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single)按下鼠标按钮时触发。
MouseMove
Public Event MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)移动鼠标时触发。
MouseUp
Public Event MouseUp(Button As Integer, Shift As Integer, X As Single, Y As Single)释放鼠标按钮时触发。
MouseEnter
Public Event MouseEnter()鼠标进入控件区域时触发。
MouseLeave
Public Event MouseLeave()鼠标离开控件区域时触发。
OLECompleteDrag
Public Event OLECompleteDrag(Effect As Long)OLE拖放操作完成时触发。
OLEDragDrop
Public Event OLEDragDrop(Data As DataObject, Effect As Long, Button As Integer, Shift As Integer, X As Single, Y As Single)OLE拖放操作放置时触发。
OLEDragOver
Public Event OLEDragOver(Data As DataObject, Effect As Long, Button As Integer, Shift As Integer, X As Single, Y As Single, State As Integer)OLE拖放操作悬停时触发。
OLEGiveFeedback
Public Event OLEGiveFeedback(Effect As Long, DefaultCursors As Boolean)OLE拖放操作给反馈时触发。
OLESetData
Public Event OLESetData(Data As DataObject, DataFormat As Integer)OLE拖放操作设置数据时触发。
OLEStartDrag
Public Event OLEStartDrag(Data As DataObject, AllowedEffects As Long)OLE拖放操作开始时触发。
辅助模块
VirtualComboBase.bas
自定义窗口类辅助模块,注册/释放"VComboBoxWndClass"窗口类,为ComboLBox添加LBS_NODATA样式。
VcbWndRegisterClass
Public Sub VcbWndRegisterClass()注册自定义窗口类。
VcbWndReleaseClass
Public Sub VcbWndReleaseClass()释放自定义窗口类。
代码示例
基本用法
' 设置虚拟组合框
With VirtualCombo1
.Style = VcbStyleDropDownList
.ListCount = 1000
.MaxDropDownItems = 15
End With
' 提供虚拟项数据
Private Sub VirtualCombo1_GetVirtualItem(ByVal Item As Long, ByRef Text As String)
Text = "项目 " & CStr(Item)
End Sub
' 查找虚拟项
Private Sub VirtualCombo1_FindVirtualItem(ByVal StartIndex As Long, _
ByVal SearchText As String, ByVal Partial As Boolean, ByRef FoundIndex As Long)
FoundIndex = -1
End Sub
' 监听下拉事件
Private Sub VirtualCombo1_DropDown()
Debug.Print "下拉列表已打开"
End Sub
Private Sub VirtualCombo1_Change()
Debug.Print "当前文本: " & VirtualCombo1.Text
End Sub