1.Start a new Visual Basic project. Form1 is created by default.
2.Place a ComboBox on the form.
3.Place a Toolbar on the form.
4.Add the following code to the Form1 code window:
Option Explicit Private Sub Form_Load()
Dim btn As Button
Me.Show
Set btn = Toolbar1.Buttons.Add()
btn.Style = tbrSeparator
Set btn = Toolbar1.Buttons.Add()
btn.Style = tbrPlaceholder
btn.Key = "ComboBox"
btn.Width = 2000 DoEvents With Combo1
.ZOrder 0
.Width = Toolbar1.Buttons("ComboBox").Width
.Top = Toolbar1.Buttons("ComboBox").Top
.Left = Toolbar1.Buttons("ComboBox").Left
End With
End Sub
5.Press the F5 key to run the project. The Form should load with a ComboBox in the Toolbar.
2.Place a ComboBox on the form.
3.Place a Toolbar on the form.
4.Add the following code to the Form1 code window:
Option Explicit Private Sub Form_Load()
Dim btn As Button
Me.Show
Set btn = Toolbar1.Buttons.Add()
btn.Style = tbrSeparator
Set btn = Toolbar1.Buttons.Add()
btn.Style = tbrPlaceholder
btn.Key = "ComboBox"
btn.Width = 2000 DoEvents With Combo1
.ZOrder 0
.Width = Toolbar1.Buttons("ComboBox").Width
.Top = Toolbar1.Buttons("ComboBox").Top
.Left = Toolbar1.Buttons("ComboBox").Left
End With
End Sub
5.Press the F5 key to run the project. The Form should load with a ComboBox in the Toolbar.
ButtonMenuClick 事件
当用户单击一个ButtonMenu对象时发生。语法Private Sub object_ButtonMenuClick([index As Integer,]ByVal ButtonMenu As ComctlLib.ButtonMenu)ButtonMenuClick 事件语法有下面几部分:部分 描述
object 一个对象表达式,其值是“应用于”列表中的一个对象。
index 一个整数,它唯一标识控件数组中的一个控件。
ButtonMenu 对被单击的ButtonMenu对象的一个引用。
说明使用ButtonMenuClick事件时,可以使用ButtonMenu对象的Parent属性决定哪一个按钮被单击。ButtonMenu对象和ButtonMenuClick 事件示例
本例在一个Toolbar 控件中添加五个 Button 对象,并且向每个 Button 对象添加二个 ButtonMenu 对象。单击ButtonMenu对象时,其行为由ButtonMenuClick事件来决定。为了试验本例,在窗体中放置一个 Toolbar 控件,将代码粘贴到代码模块的声明部分。Option ExplicitPrivate Sub Form_Load()
Dim i As Integer
Dim btn As Button
' 添加五个 Button 对象到 Toolbar 控件。
For i = 1 To 5
Set btn = Toolbar1.Buttons.Add(Caption:= i, Style:= tbrDropDown)
' 添加两个 ButtonMenu 对象到每一个Button。
btn.ButtonMenus.Add Text:="Help"
btn.ButtonMenus.Add Text:="Options"
Next i
End SubPrivate Sub Toolbar1_ButtonMenuClick(ByVal ButtonMenu As ComctlLib.ButtonMenu)
Select Case ButtonMenu.Index
Case 1
MsgBox "Press the button."
Case 2
MsgBox "Offer some option"
End Select
End Sub