滑块控件(Slider)
提供可自定义的滑块控件,支持水平/垂直方向、刻度样式、选择范围、自绘和OLE拖放。
枚举
SldOrientationConstants
控件方向常量。
| 常量 | 值 | 说明 |
|---|---|---|
| SldOrientationHorizontal | 0 | 水平方向 |
| SldOrientationVertical | 1 | 垂直方向 |
SldTipSideConstants
提示文本位置常量。
| 常量 | 值 | 说明 |
|---|---|---|
| SldTipSideAboveLeft | 0 | 提示显示在上方/左侧 |
| SldTipSideBelowRight | 1 | 提示显示在下方/右侧 |
SldTickStyleConstants
刻度样式常量。
| 常量 | 值 | 说明 |
|---|---|---|
| SldTickStyleBottomRight | 0 | 底部/右侧刻度 |
| SldTickStyleTopLeft | 1 | 顶部/左侧刻度 |
| SldTickStyleBoth | 2 | 两侧刻度 |
| SldTickStyleNone | 3 | 无刻度 |
SldDrawModeConstants
绘制模式常量。
| 常量 | 值 | 说明 |
|---|---|---|
| SldDrawModeNormal | 0 | 正常绘制 |
| SldDrawModeOwnerDraw | 1 | 自绘模式 |
SldOwnerDrawItemConstants
自绘项常量。
| 常量 | 值 | 说明 |
|---|---|---|
| SldOwnerDrawItemTics | 1 | 刻度线 |
| SldOwnerDrawItemThumb | 2 | 滑块 |
| SldOwnerDrawItemChannel | 3 | 通道 |
属性
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句柄。
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)返回/设置背景色。
Enabled
Public Property Get Enabled() As Boolean
Public Property Let Enabled(ByVal Value As Boolean)返回/设置对象是否能响应用户事件。
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)返回/设置从右到左显示方向。
RightToLeftLayout
Public Property Get RightToLeftLayout() As Boolean
Public Property Let RightToLeftLayout(ByVal Value As Boolean)返回/设置从右到左布局。
RightToLeftMode
Public Property Get RightToLeftMode() As CCRightToLeftModeConstants
Public Property Let RightToLeftMode(ByVal Value As CCRightToLeftModeConstants)返回/设置从右到左模式。参见通用枚举。
Min
Public Property Get Min() As Long
Public Property Let Min(ByVal Value As Long)返回/设置最小值。
Max
Public Property Get Max() As Long
Public Property Let Max(ByVal Value As Long)返回/设置最大值。
Value
Public Property Get Value() As Long
Public Property Let Value(ByVal NewValue As Long)返回/设置当前值。
TickFrequency
Public Property Get TickFrequency() As Long
Public Property Let TickFrequency(ByVal Value As Long)返回/设置刻度频率。
Orientation
Public Property Get Orientation() As SldOrientationConstants
Public Property Let Orientation(ByVal Value As SldOrientationConstants)返回/设置控件方向。
SmallChange
Public Property Get SmallChange() As Long
Public Property Let SmallChange(ByVal Value As Long)返回/设置按下箭头键时的变化量。
LargeChange
Public Property Get LargeChange() As Long
Public Property Let LargeChange(ByVal Value As Long)返回/设置按下PageUp/PageDown或点击通道时的变化量。
TickStyle
Public Property Get TickStyle() As SldTickStyleConstants
Public Property Let TickStyle(ByVal Value As SldTickStyleConstants)返回/设置刻度样式。
ShowTip
Public Property Get ShowTip() As Boolean
Public Property Let ShowTip(ByVal Value As Boolean)返回/设置是否显示值提示。
TipSide
Public Property Get TipSide() As SldTipSideConstants
Public Property Let TipSide(ByVal Value As SldTipSideConstants)返回/设置提示显示位置。
SelectRange
Public Property Get SelectRange() As Boolean
Public Property Let SelectRange(ByVal Value As Boolean)返回/设置是否启用选择范围。
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)返回/设置选择范围的长度。
Transparent
Public Property Get Transparent() As Boolean
Public Property Let Transparent(ByVal Value As Boolean)返回/设置控件背景是否透明。
HideThumb
Public Property Get HideThumb() As Boolean
Public Property Let HideThumb(ByVal Value As Boolean)返回/设置是否隐藏滑块。
Reversed
Public Property Get Reversed() As Boolean
Public Property Let Reversed(ByVal Value As Boolean)返回/设置是否反转滑块方向。
DrawMode
Public Property Get DrawMode() As SldDrawModeConstants
Public Property Let DrawMode(ByVal Value As SldDrawModeConstants)返回/设置绘制模式。
ThumbLeft
Public Property Get ThumbLeft() As Single返回滑块左边距。
ThumbTop
Public Property Get ThumbTop() As Single返回滑块顶边距。
ThumbWidth
Public Property Get ThumbWidth() As Single返回滑块宽度。
ThumbHeight
Public Property Get ThumbHeight() As Single返回滑块高度。
ChannelLeft
Public Property Get ChannelLeft() As Single返回通道左边距。
ChannelTop
Public Property Get ChannelTop() As Single返回通道顶边距。
ChannelWidth
Public Property Get ChannelWidth() As Single返回通道宽度。
ChannelHeight
Public Property Get ChannelHeight() As Single返回通道高度。
方法
Refresh
Public Sub Refresh()强制完全重绘对象。
ClearSel
Public Sub ClearSel()清除选择范围。
GetNumTicks
Public Function GetNumTicks() As Long返回刻度数量。
GetTickPosition
Public Function GetTickPosition(ByVal Index As Long) As Single返回指定刻度的位置。
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顺序。
事件
Click
Public Event Click()用户单击控件时触发。
Scroll
Public Event Scroll()用户拖动滑块时触发。
Change
Public Event Change()值改变后触发。
ContextMenu
Public Event ContextMenu(ByVal X As Single, ByVal Y As Single)右键点击控件时触发。
ModifyTipText
Public Event ModifyTipText(ByRef Text As String)提示文本即将显示时触发,可修改提示文本。
ItemDraw
Public Event ItemDraw(ByVal Item As SldOwnerDrawItemConstants, ByRef Cancel As Boolean, ByVal ItemState As Long, ByVal hDC As Long, ByVal Left As Long, ByVal Top As Long, ByVal Right As Long, ByVal Bottom As Long)自绘项时触发。Item为自绘项类型,Cancel可取消默认绘制,hDC为设备上下文。
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拖放操作开始时触发。
代码示例
基本用法
' 设置滑块控件
With Slider1
.Min = 0
.Max = 100
.Value = 50
.TickFrequency = 10
.SmallChange = 1
.LargeChange = 10
.SelectRange = True
.SelStart = 20
.SelLength = 60
End With
' 响应值变化
Private Sub Slider1_Change()
Debug.Print "当前值: " & Slider1.Value
End Sub
' 自定义提示文本
Private Sub Slider1_ModifyTipText(ByRef Text As String)
Text = "进度: " & Slider1.Value & "%"
End Sub