- Class Overview
- Class Architecture
- Properties
- Methods
- Events
- Constants and Enumerations
- Implementation Details
- Dependencies
The clsSlider class implements a custom slider control for VBA UserForms. The slider allows users to select a value within a specified range by dragging a button along a track. It supports both horizontal and vertical orientations and provides customizable appearance and behavior options.
- Horizontal and vertical orientation support
- Configurable min/max values and initial value
- Customizable appearance (colors, icons, formatting)
- Visible/hidden value label with positioning options
- Event handling for value changes and clicks
- Lock functionality to prevent user interaction
- Automatic positioning of value label (top, left, right, bottom)
Defines possible positions for the slider value label:
Top(1) - value label appears above the sliderLeft- value label appears to the left of the sliderRight- value label appears to the right of the sliderBottom- value label appears below the slider
| Property | Type | Description |
|---|---|---|
Value |
Single | Current slider value |
MinValue |
Single | Minimum slider value |
MaxValue |
Single | Maximum slider value |
IsHorizontal |
Boolean | Flag for horizontal orientation |
Locked |
Boolean | Flag for locking the slider |
Visible |
Boolean | Visibility state of all slider elements |
Enabled |
Boolean | Enabled state of the slider |
VisibleLabelValue |
Boolean | Visibility state of the slider value label |
ForeColorValue |
XlRgbColor | Text color of the slider value label |
ForeColorBtn |
XlRgbColor | Text color of the slider button |
BackColorFull |
XlRgbColor | Color of the filled part of the slider line |
BackColorEmpty |
XlRgbColor | Color of the empty part of the slider line |
PositionLabelValue |
PositionValue | Position of the slider value label |
FormatValue |
String | Format for displaying the slider value |
ForeColorValue |
XlRgbColor | Text color of the slider value label |
ForeColorBtn |
XlRgbColor | Text color of the slider button |
Name |
String | Name of the main slider label |
Icon |
Long | Icon on the slider button (as a Unicode character value) |
Value- Gets or sets the current value of the sliderMinValue- Gets or sets the minimum value of the sliderMaxValue- Gets or sets the maximum value of the sliderIsHorizontal- Gets whether the slider is horizontalLocked- Gets or sets the lock state of the sliderVisible- Gets or sets the visibility state of all slider elementsEnabled- Gets or sets the enabled state of the sliderVisibleLabelValue- Gets or sets the visibility state of the slider value labelForeColorValue- Gets or sets the text color of the slider value labelForeColorBtn- Gets or sets the text color of the slider buttonBackColorFull- Gets or sets the color of the filled part of the slider lineBackColorEmpty- Gets or sets the color of the empty part of the slider linePositionLabelValue- Gets or sets the position of the slider value labelFormatValue- Gets or sets the format for displaying the slider valueName- Gets the name of the main slider labelIcon- Gets or sets the icon on the slider button
Version- Gets version information about the classItems- Gets the collection of all slider itemsCount- Gets the number of items in the collection
Initializes the slider with specified parameters.
Syntax:
Public Sub Initialize(ByRef labelSlider As MSForms.Label, _
ByVal Value As Single, _
ByVal MinValue As Single, _
ByVal MaxValue As Single, _
ByVal VisibleLabelValue As Boolean, _
Optional FormatValue As String = vbNullString, _
Optional PositionValue As PositionValue = Top, _
Optional BackColorEmpty As XlRgbColor = rgbLightGray, _
Optional BackColorFull As XlRgbColor = rgbGreenYellow, _
Optional ForeColorBtn As XlRgbColor = rgbBlack, _
Optional ForeColorValue As XlRgbColor = rgbBlack, _
Optional Icon As Long = 5963)Parameters:
labelSlider- the main label that will be used as the empty slider lineValue- initial value of the sliderMinValue- minimum value of the sliderMaxValue- maximum value of the sliderVisibleLabelValue- visibility of the value labelFormatValue- format for displaying the value (default vbNullString)PositionValue- position of the value label (default Top)BackColorEmpty- color of the empty part of the line (default rgbLightGray)BackColorFull- color of the filled part of the line (default rgbGreenYellow)ForeColorBtn- color of the button (default rgbBlack)ForeColorValue- color of the value (default rgbBlack)Icon- icon on the button (default 59963)
Event raised when the slider button is clicked.
Syntax:
Private Sub mLabelBtn_Click()Event raised when the slider value changes.
Syntax:
Private Sub mLabelBtn_MouseMove(ByVal Button As Integer, ByVal Shift As Integer, ByVal X As Single, ByVal Y As Single)Public Enum PositionValue
Top = 1 ' Position of the value label above the slider
Left ' Position of the value label to the left of the slider
Right ' Position of the value label to the right of the slider
Bottom ' Position of the value label below the slider
End EnumThe class supports both horizontal and vertical orientations:
- Horizontal: The slider moves left and right
- Vertical: The slider moves up and down
The slider consists of multiple visual elements:
- Main slider line (empty part)
- Filled slider line (filled part)
- Slider button (movable element)
- Value label (displays current value)
The class automatically handles slider events:
Click- raises the Click event when the button is clickedMouseMove- updates the slider position and value when dragging
- MSForms library for Label controls
- XlRgbColor constants for color properties