ツールバーにフライアウト ツールバー ボタンを追加するには、AddToolbarButton メソッドを使用します。このメソッドは新しい ToolbarItem オブジェクトを作成し、指定されたツールバーに追加します。
AddToolbarButton メソッドは入力として、Index、Name、HelpString、Macro、FlyoutButton という 5 つのパラメータを受け取ります。FlyoutButton パラメータを TRUE に設定することによって、新しいボタンがフライアウト ボタンとして作成されます。このメソッドからの戻り値は、新しいフライアウト ツールバーです。このフライアウト ツールバーは通常のツールバーと同じように配置できます。
以下の例は、2 つのツールバーを作成します。最初のツールバーにはフライアウト ボタンが含まれます。2 番目のツールバーは、最初に作成されたツールバーのフライアウト ボタンにアタッチされます。
Sub Ch6_AddFlyoutButton()
Dim currMenuGroup As AcadMenuGroup
Set currMenuGroup = ThisDrawing.Application. _
MenuGroups.Item(0)
' Create the first toolbar
Dim FirstToolbar As AcadToolbar
Set FirstToolbar = currMenuGroup.Toolbars. _
Add("FirstToolbar")
' Add a flyout button to the first menu on the menu bar
Dim FlyoutButton As AcadToolbarItem
Set FlyoutButton = FirstToolbar.AddToolbarButton _
("", "Flyout", "Demonstrates a flyout button", _
"OPEN", True)
' Create the second toolbar. This will be attached to
' the first toolbar through the flyout button.
Dim SecondToolbar As AcadToolbar
Set SecondToolbar = currMenuGroup.Toolbars. _
Add("SecondToolbar")
' Add a button to the next toolbar
Dim newButton As AcadToolbarItem
Dim openMacro As String
' Assign the macro the VB equivalent of "ESC ESC _open "
openMacro = Chr(3) + Chr(3) + "_open "
Set newButton = SecondToolbar.AddToolbarButton _
("", "NewButton", "Open a file.", openMacro)
' Attach the second toolbar to the flyout
' button on the first toolbar
FlyoutButton.AttachToolbarToFlyout currMenuGroup.Name, _
SecondToolbar.Name
' Display the first toolbar, hide the second toolbar
FirstToolbar.Visible = True
SecondToolbar.Visible = False
End Sub