ToolBar Control
Provides a customizable toolbar, supporting flat/standard styles, dropdown buttons, button menus, user customization, and OLE drag-and-drop.
Enumerations
TbrStyleConstants
Toolbar style constants.
| Constant | Value | Description |
|---|---|---|
| TbrStyleStandard | 0 | Standard toolbar style |
| TbrStyleFlat | 1 | Flat toolbar style |
TbrTextAlignConstants
Button text alignment constants.
| Constant | Value | Description |
|---|---|---|
| TbrTextAlignBottom | 0 | Text displayed at the bottom of the button |
| TbrTextAlignRight | 1 | Text displayed to the right of the button |
TbrOrientationConstants
Toolbar orientation constants.
| Constant | Value | Description |
|---|---|---|
| TbrOrientationHorizontal | 0 | Horizontal orientation |
| TbrOrientationVertical | 1 | Vertical orientation |
TbrButtonStyleConstants
Button style constants.
| Constant | Value | Description |
|---|---|---|
| TbrButtonDefault | 0 | Default button style |
| TbrButtonCheck | 1 | Check button style |
| TbrButtonCheckGroup | 2 | Check group button style (mutually exclusive within group) |
| TbrButtonSeparator | 3 | Separator |
| TbrButtonDropDown | 4 | Dropdown button style |
| TbrButtonWholeDropDown | 5 | Whole dropdown button style |
TbrButtonValueConstants
Button state value constants.
| Constant | Value | Description |
|---|---|---|
| TbrButtonUnpressed | 0 | Unpressed state |
| TbrButtonPressed | 1 | Pressed state |
Properties
Name
Public Property Get Name() As StringReturns the name used to identify the object in code.
Tag
Public Property Get Tag() As String
Public Property Let Tag(ByVal Value As String)Stores extra data needed by the program.
Parent
Public Property Get Parent() As ObjectReturns the object that contains this object.
Container
Public Property Get Container() As Object
Public Property Set Container(ByVal Value As Object)Returns/sets the object's container.
Left
Public Property Get Left() As Single
Public Property Let Left(ByVal Value As Single)Returns/sets the distance between the object and the left edge of its container.
Top
Public Property Get Top() As Single
Public Property Let Top(ByVal Value As Single)Returns/sets the distance between the object and the top edge of its container.
Width
Public Property Get Width() As Single
Public Property Let Width(ByVal Value As Single)Returns/sets the width of the object.
Height
Public Property Get Height() As Single
Public Property Let Height(ByVal Value As Single)Returns/sets the height of the object.
Visible
Public Property Get Visible() As Boolean
Public Property Let Visible(ByVal Value As Boolean)Returns/sets whether the object is visible.
ToolTipText
Public Property Get ToolTipText() As String
Public Property Let ToolTipText(ByVal Value As String)Returns/sets the tooltip text displayed when the mouse hovers over the control.
WhatsThisHelpID
Public Property Get WhatsThisHelpID() As Long
Public Property Let WhatsThisHelpID(ByVal Value As Long)Returns/sets the associated context-sensitive help ID.
Align
Public Property Get Align() As Integer
Public Property Let Align(ByVal Value As Integer)Returns/sets the alignment of the control on its form.
DragIcon
Public Property Get DragIcon() As IPictureDisp
Public Property Let DragIcon(ByVal Value As IPictureDisp)
Public Property Set DragIcon(ByVal Value As IPictureDisp)Returns/sets the icon displayed during a drag-and-drop operation.
DragMode
Public Property Get DragMode() As Integer
Public Property Let DragMode(ByVal Value As Integer)Returns/sets the drag mode (manual or automatic).
hWnd
Public Property Get hWnd() As LongPtrReturns the control handle.
hWndUserControl
Public Property Get hWndUserControl() As LongPtrReturns the UserControl handle.
Font
Public Property Get Font() As StdFont
Public Property Let Font(ByVal NewFont As StdFont)
Public Property Set Font(ByVal NewFont As StdFont)Returns/sets the font.
VisualStyles
Public Property Get VisualStyles() As Boolean
Public Property Let VisualStyles(ByVal Value As Boolean)Returns/sets whether visual styles are enabled. Requires comctl32.dll 6.0 or later.
Enabled
Public Property Get Enabled() As Boolean
Public Property Let Enabled(ByVal Value As Boolean)Returns/sets whether the object can respond to user-generated events.
OLEDropMode
Public Property Get OLEDropMode() As OLEDropModeConstants
Public Property Let OLEDropMode(ByVal Value As OLEDropModeConstants)Returns/sets whether the object can act as an OLE drop target.
MousePointer
Public Property Get MousePointer() As CCMousePointerConstants
Public Property Let MousePointer(ByVal Value As CCMousePointerConstants)Returns/sets the pointer type displayed when the mouse hovers over the control. See common enumerations.
MouseIcon
Public Property Get MouseIcon() As IPictureDisp
Public Property Let MouseIcon(ByVal Value As IPictureDisp)
Public Property Set MouseIcon(ByVal Value As IPictureDisp)Returns/sets the custom mouse icon.
MouseTrack
Public Property Get MouseTrack() As Boolean
Public Property Let MouseTrack(ByVal Value As Boolean)Returns/sets whether events are raised when the mouse enters or leaves the control.
RightToLeft
Public Property Get RightToLeft() As Boolean
Public Property Let RightToLeft(ByVal Value As Boolean)Returns/sets the right-to-left display direction.
RightToLeftLayout
Public Property Get RightToLeftLayout() As Boolean
Public Property Let RightToLeftLayout(ByVal Value As Boolean)Returns/sets the right-to-left layout.
RightToLeftMode
Public Property Get RightToLeftMode() As CCRightToLeftModeConstants
Public Property Let RightToLeftMode(ByVal Value As CCRightToLeftModeConstants)Returns/sets the right-to-left mode. See common enumerations.
ImageList
Public Property Get ImageList() As Variant
Public Property Let ImageList(ByVal Value As Variant)
Public Property Set ImageList(ByVal Value As Variant)Returns/sets the associated ImageList control. Can be an object reference, a string key name, or a LongPtr handle.
DisabledImageList
Public Property Get DisabledImageList() As Variant
Public Property Let DisabledImageList(ByVal Value As Variant)
Public Property Set DisabledImageList(ByVal Value As Variant)Returns/sets the ImageList control used for the disabled button state.
HotImageList
Public Property Get HotImageList() As Variant
Public Property Let HotImageList(ByVal Value As Variant)
Public Property Set HotImageList(ByVal Value As Variant)Returns/sets the ImageList control used for the hot button state.
PressedImageList
Public Property Get PressedImageList() As Variant
Public Property Let PressedImageList(ByVal Value As Variant)
Public Property Set PressedImageList(ByVal Value As Variant)Returns/sets the ImageList control used for the pressed button state.
BackColor
Public Property Get BackColor() As OLE_COLOR
Public Property Let BackColor(ByVal Value As OLE_COLOR)Returns/sets the background color.
Style
Public Property Get Style() As TbrStyleConstants
Public Property Let Style(ByVal Value As TbrStyleConstants)Returns/sets the toolbar style.
TextAlignment
Public Property Get TextAlignment() As TbrTextAlignConstants
Public Property Let TextAlignment(ByVal Value As TbrTextAlignConstants)Returns/sets the button text alignment.
Orientation
Public Property Get Orientation() As TbrOrientationConstants
Public Property Let Orientation(ByVal Value As TbrOrientationConstants)Returns/sets the toolbar orientation.
Divider
Public Property Get Divider() As Boolean
Public Property Let Divider(ByVal Value As Boolean)Returns/sets whether a divider line is displayed.
ShowTips
Public Property Get ShowTips() As Boolean
Public Property Let ShowTips(ByVal Value As Boolean)Returns/sets whether tooltips are displayed.
Wrappable
Public Property Get Wrappable() As Boolean
Public Property Let Wrappable(ByVal Value As Boolean)Returns/sets whether buttons wrap automatically.
AllowCustomize
Public Property Get AllowCustomize() As Boolean
Public Property Let AllowCustomize(ByVal Value As Boolean)Returns/sets whether the user can customize the toolbar.
AltDrag
Public Property Get AltDrag() As Boolean
Public Property Let AltDrag(ByVal Value As Boolean)Returns/sets whether Alt+drag is allowed to customize the toolbar.
DoubleBuffer
Public Property Get DoubleBuffer() As Boolean
Public Property Let DoubleBuffer(ByVal Value As Boolean)Returns/sets whether double-buffered drawing is enabled.
ButtonHeight
Public Property Get ButtonHeight() As Single
Public Property Let ButtonHeight(ByVal Value As Single)Returns/sets the button height.
ButtonWidth
Public Property Get ButtonWidth() As Single
Public Property Let ButtonWidth(ByVal Value As Single)Returns/sets the button width.
MinButtonWidth
Public Property Get MinButtonWidth() As Single
Public Property Let MinButtonWidth(ByVal Value As Single)Returns/sets the minimum button width.
MaxButtonWidth
Public Property Get MaxButtonWidth() As Single
Public Property Let MaxButtonWidth(ByVal Value As Single)Returns/sets the maximum button width.
InsertMarkColor
Public Property Get InsertMarkColor() As OLE_COLOR
Public Property Let InsertMarkColor(ByVal Value As OLE_COLOR)Returns/sets the insert mark color.
Transparent
Public Property Get Transparent() As Boolean
Public Property Let Transparent(ByVal Value As Boolean)Returns/sets whether the toolbar is transparent.
HotTracking
Public Property Get HotTracking() As Boolean
Public Property Let HotTracking(ByVal Value As Boolean)Returns/sets whether hot tracking is enabled.
HideClippedButtons
Public Property Get HideClippedButtons() As Boolean
Public Property Let HideClippedButtons(ByVal Value As Boolean)Returns/sets whether clipped buttons are hidden.
AnchorHot
Public Property Get AnchorHot() As Boolean
Public Property Let AnchorHot(ByVal Value As Boolean)Returns/sets whether hot items are anchored.
MaxTextRows
Public Property Get MaxTextRows() As Integer
Public Property Let MaxTextRows(ByVal Value As Integer)Returns/sets the maximum number of text rows.
Buttons
Public Property Get Buttons() As TbrButtonsReturns the buttons collection.
Methods
OLEDrag
Public Sub OLEDrag()Initiates an OLE drag-and-drop operation.
Drag
Public Sub Drag(Optional ByRef Action As Variant)Starts, ends, or cancels a drag operation.
ZOrder
Public Sub ZOrder(Optional ByRef Position As Variant)Sets the Z-order.
Refresh
Public Sub Refresh()Forces a complete redraw of the object.
Events
Click
Public Event Click()Raised when the user clicks the control.
DblClick
Public Event DblClick()Raised when the user double-clicks the control.
Resize
Public Event Resize()Raised when the control is resized.
BeginCustomization
Public Event BeginCustomization()Raised when toolbar customization begins.
InitCustomizationDialog
Public Event InitCustomizationDialog(ByVal hDlg As LongPtr, ByRef HideHelpButton As Boolean)Raised when initializing the customization dialog. hDlg is the dialog handle; HideHelpButton controls whether the Help button is hidden.
CustomizationChange
Public Event CustomizationChange()Raised when a toolbar customization change occurs.
ResetCustomizations
Public Event ResetCustomizations(ByRef CloseDialog As Boolean)Raised when customizations are reset. CloseDialog controls whether the dialog is closed.
CustomizationHelp
Public Event CustomizationHelp()Raised when the user clicks Help in the customization dialog.
EndCustomization
Public Event EndCustomization()Raised when toolbar customization ends.
ButtonClick
Public Event ButtonClick(ByVal Button As TbrButton)Raised when the user clicks a button.
ButtonDrag
Public Event ButtonDrag(ByVal Button As TbrButton, ByVal MouseButton As Integer)Raised when the user drags a button.
ButtonHotChanged
Public Event ButtonHotChanged(ByVal Button As TbrButton, ByVal Hot As Boolean)Raised when a button's hot state changes.
ButtonDropDown
Public Event ButtonDropDown(ByVal Button As TbrButton)Raised when a dropdown button is clicked.
ButtonMenuClick
Public Event ButtonMenuClick(ByVal ButtonMenu As TbrButtonMenu)Raised when a dropdown menu item is clicked.
ButtonMenuClick2
Public Event ButtonMenuClick2(ByVal Button As TbrButton, ByVal ID As Long)Raised when a dropdown menu item is clicked, providing both the parent button and the menu item ID.
ButtonMouseEnter
Public Event ButtonMouseEnter(ByVal Button As TbrButton)Raised when the mouse enters a button area.
ButtonMouseLeave
Public Event ButtonMouseLeave(ByVal Button As TbrButton)Raised when the mouse leaves a button area.
MouseDown
Public Event MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single)Raised when a mouse button is pressed.
MouseMove
Public Event MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)Raised when the mouse is moved.
MouseUp
Public Event MouseUp(Button As Integer, Shift As Integer, X As Single, Y As Single)Raised when a mouse button is released.
MouseEnter
Public Event MouseEnter()Raised when the mouse enters the control area.
MouseLeave
Public Event MouseLeave()Raised when the mouse leaves the control area.
OLECompleteDrag
Public Event OLECompleteDrag(Effect As Long)Raised when an OLE drag-and-drop operation is completed.
OLEDragDrop
Public Event OLEDragDrop(Data As DataObject, Effect As Long, Button As Integer, Shift As Integer, X As Single, Y As Single)Raised when an OLE drag-and-drop operation is dropped.
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)Raised during an OLE drag-and-drop hover.
OLEGiveFeedback
Public Event OLEGiveFeedback(Effect As Long, DefaultCursors As Boolean)Raised when OLE drag-and-drop gives feedback.
OLESetData
Public Event OLESetData(Data As DataObject, DataFormat As Integer)Raised when OLE drag-and-drop sets data.
OLEStartDrag
Public Event OLEStartDrag(Data As DataObject, AllowedEffects As Long)Raised when an OLE drag-and-drop operation starts.
Sub-Objects
TbrButton Class
Toolbar button object.
TbrButton Properties
Index
Public Property Get Index() As LongThe index of the button in the collection.
Key
Public Property Get Key() As String
Public Property Let Key(ByVal Value As String)The button's unique identifier key.
Tag
Public Property Get Tag() As Variant
Public Property Let Tag(ByVal Value As Variant)Extra data.
ID
Public Property Get ID() As LongButton ID.
Caption
Public Property Get Caption() As String
Public Property Let Caption(ByVal Value As String)Button caption.
Style
Public Property Get Style() As TbrButtonStyleConstants
Public Property Let Style(ByVal Value As TbrButtonStyleConstants)Button style.
Image
Public Property Get Image() As Variant
Public Property Let Image(ByVal Value As Variant)Button image.
ImageIndex
Public Property Get ImageIndex() As LongImage index.
ToolTipText
Public Property Get ToolTipText() As String
Public Property Let ToolTipText(ByVal Value As String)ToolTip text.
Description
Public Property Get Description() As String
Public Property Let Description(ByVal Value As String)Button description.
Value
Public Property Get Value() As TbrButtonValueConstants
Public Property Let Value(ByVal Value As TbrButtonValueConstants)Button value (pressed/unpressed state).
Enabled
Public Property Get Enabled() As Boolean
Public Property Let Enabled(ByVal Value As Boolean)Whether enabled.
Visible
Public Property Get Visible() As Boolean
Public Property Let Visible(ByVal Value As Boolean)Whether visible.
MixedState
Public Property Get MixedState() As Boolean
Public Property Let MixedState(ByVal Value As Boolean)Whether in mixed state (tri-state checkbox).
HighLighted
Public Property Get HighLighted() As Boolean
Public Property Let HighLighted(ByVal Value As Boolean)Whether highlighted.
NoImage
Public Property Get NoImage() As Boolean
Public Property Let NoImage(ByVal Value As Boolean)Whether no image is displayed.
NoPrefix
Public Property Get NoPrefix() As Boolean
Public Property Let NoPrefix(ByVal Value As Boolean)Whether mnemonic prefix (&) is not processed.
AutoSize
Public Property Get AutoSize() As Boolean
Public Property Let AutoSize(ByVal Value As Boolean)Whether auto-sized.
CustomWidth
Public Property Get CustomWidth() As Single
Public Property Let CustomWidth(ByVal Value As Single)Custom width.
ForeColor
Public Property Get ForeColor() As OLE_COLOR
Public Property Let ForeColor(ByVal Value As OLE_COLOR)Foreground color.
Position
Public Property Get Position() As Long
Public Property Let Position(ByVal Value As Long)Button position.
Hot
Public Property Get Hot() As BooleanWhether in hot state.
Left
Public Property Get Left() As SingleButton left edge distance.
Top
Public Property Get Top() As SingleButton top edge distance.
Width
Public Property Get Width() As SingleButton width.
Height
Public Property Get Height() As SingleButton height.
ButtonMenus
Public Property Get ButtonMenus() As TbrButtonMenusDropdown menu collection.
hMenu
Public Property Get hMenu() As LongPtrMenu handle.
TbrButtonMenu Class
Button dropdown menu item object.
TbrButtonMenu Properties
Index
Public Property Get Index() As LongMenu item index.
Key
Public Property Get Key() As String
Public Property Let Key(ByVal Value As String)Unique identifier key.
Tag
Public Property Get Tag() As Variant
Public Property Let Tag(ByVal Value As Variant)Extra data.
Text
Public Property Get Text() As String
Public Property Let Text(ByVal Value As String)Menu item text.
Enabled
Public Property Get Enabled() As Boolean
Public Property Let Enabled(ByVal Value As Boolean)Whether enabled.
Visible
Public Property Get Visible() As Boolean
Public Property Let Visible(ByVal Value As Boolean)Whether visible.
Checked
Public Property Get Checked() As Boolean
Public Property Let Checked(ByVal Value As Boolean)Whether checked.
Separator
Public Property Get Separator() As Boolean
Public Property Let Separator(ByVal Value As Boolean)Whether it is a separator.
Picture
Public Property Get Picture() As IPictureDisp
Public Property Set Picture(ByVal Value As IPictureDisp)Menu item icon.
Parent
Public Property Get Parent() As TbrButtonParent button.
TbrButtonMenus Class
Button dropdown menu item collection.
TbrButtonMenus Members
NewEnum
Public Function NewEnum() As IUnknownEnumerator (hidden).
Add
Public Function Add(Optional ByVal Index As Variant, Optional ByVal Key As Variant, Optional ByVal Text As Variant) As TbrButtonMenuAdds a menu item.
Item
Public Function Item(ByVal Index As Variant) As TbrButtonMenuGets a menu item (default member).
Exists
Public Function Exists(ByVal Index As Variant) As BooleanChecks if a menu item exists.
Count
Public Property Get Count() As LongMenu item count.
Clear
Public Sub Clear()Clears all menu items.
Remove
Public Sub Remove(ByVal Index As Variant)Removes a menu item.
TbrButtons Class
Toolbar buttons collection.
TbrButtons Members
NewEnum
Public Function NewEnum() As IUnknownEnumerator (hidden).
Add
Public Function Add(Optional ByVal Index As Variant, Optional ByVal Key As Variant, Optional ByVal Caption As Variant, Optional ByVal Style As Variant, Optional ByVal Image As Variant) As TbrButtonAdds a button.
Item
Public Function Item(ByVal Index As Variant) As TbrButtonGets a button (default member).
Exists
Public Function Exists(ByVal Index As Variant) As BooleanChecks if a button exists.
Count
Public Property Get Count() As LongButton count.
Clear
Public Sub Clear()Clears all buttons.
Remove
Public Sub Remove(ByVal Index As Variant)Removes a button.
TbrButtonProperties Class
Internal button properties object (Friend access).
FInit
Friend Property Get FInit() As Boolean
Friend Property Let FInit(ByVal Value As Boolean)Internal initialization flag.
ForeColor
Public Property Get ForeColor() As OLE_COLOR
Public Property Let ForeColor(ByVal Value As OLE_COLOR)Foreground color.
Code Examples
Basic Usage
' Create toolbar and add buttons
With ToolBar1.Buttons
.Add , "New", "New", tbrButtonDefault, 1
.Add , "Open", "Open", tbrButtonDefault, 2
.Add , , , tbrButtonSeparator
.Add , "Bold", "Bold", tbrButtonCheck, 3
End With
' Add dropdown menu to a button
Dim btn As TbrButton
Set btn = ToolBar1.Buttons.Add(, "Font", "Font", tbrButtonDropDown, 4)
With btn.ButtonMenus
.Add , "Arial", "Arial"
.Add , "Courier", "Courier New"
.Add , , , , , True ' Separator
.Add , "Tahoma", "Tahoma"
End With
' Handle button click
Private Sub ToolBar1_ButtonClick(ByVal Button As TbrButton)
Select Case Button.Key
Case "New": MsgBox "New file"
Case "Open": MsgBox "Open file"
Case "Bold": MsgBox "Bold: " & Button.Value
End Select
End Sub
' Handle dropdown menu click
Private Sub ToolBar1_ButtonMenuClick(ByVal ButtonMenu As TbrButtonMenu)
MsgBox "Selected font: " & ButtonMenu.Text
End Sub