ツールバーのドッキングまたは浮動は、プログラムによって行うことができます。
浮動ツールバーにするには、ツールバーの Float メソッドを使用します。Float メソッドは入力として、Top、Left、NumberFloatRows の 3 つのパラメータを受け取ります。Top パラメータと Left パラメータには、ツールバーの上端と左端のピクセル位置を指定します。NumberFloatRows パラメータには、水平ツールバーで作成する行数を指定します。この数は 1 以上でなければなりません。ツールバーのボタンは、指定された行数に均等に配分されます。垂直ツールバーの場合、この数は列数を示します。
ツールバーをドッキングするには、ツールバーの Dock メソッドを使用します。 Dock メソッドは入力として Side、Row、Column という 3 つのパラメータを受け取ります。Side パラメータには、ドッキングする位置としてツールバーの面を指定します。ツールバーの上、下、左、右のいずれかを指定できます。Row パラメータと Column パラメータには、ツールバーをドッキングする位置として、ドッキングされるツールバーの既存の行と列の番号を指定します。
DockStatus プロパティを使用すると、ツールバーがドッキングされているかどうかをクエリーできます。ツールバーがドッキングされている場合は DockStatus プロパティから TRUE が返され、浮動状態の場合は FALSE が返されます。
この例では、ボタンが 3 つある新しいツールバーを作成します。次に、このツールバーを表示して画面の左側にドッキングします。
Sub Ch6_DockToolbar()
Dim currMenuGroup As AcadMenuGroup
Set currMenuGroup = ThisDrawing.Application. _
MenuGroups.Item(0)
' Create the new toolbar
Dim newToolbar As AcadToolbar
Set newToolbar = currMenuGroup.Toolbars. _
Add("TestToolbar")
' Add three buttons to the new toolbar.
' All three buttons will have the same macro attached.
Dim newButton1 As AcadToolbarItem
Dim newButton2 As AcadToolbarItem
Dim newButton3 As AcadToolbarItem
Dim openMacro As String
' Assign the macro the VB equivalent of "ESC ESC _open "
openMacro = Chr(3) + Chr(3) + "_open "
Set newButton1 = newToolbar.AddToolbarButton _
("", "NewButton1", "Open a file.", openMacro)
Set newButton2 = newToolbar.AddToolbarButton _
("", "NewButton2", "Open a file.", openMacro)
Set newButton3 = newToolbar.AddToolbarButton _
("", "NewButton3", "Open a file.", openMacro)
' Display the toolbar
newToolbar.Visible = True
' Dock the toolbar to the left of the screen.
newToolbar.Dock acToolbarDockLeft
End Sub