Float and Dock Toolbars
 
 
 

Toolbars can be docked or floated programmatically.

To float a toolbar, use the Float method for the toolbar. The Float method takes three parameters as input: Top, Left, and NumberFloatRows. The Top and Left parameters specify the pixel location for the top and left edge of the toolbar. The NumberFloatRows parameter specifies the number of rows with which to create a horizontal toolbar. This number must be equal to or greater than one. The buttons of the toolbar will be distributed equally across the number of rows specified. For vertically aligned toolbars, this value specifies the number of columns.

To dock a toolbar, use the Dock method for the toolbar. The Dock method takes three parameters as input: Side, Row, and Column. The Side parameter specifies the side of the toolbar that you will be positioning in the docking maneuver. You can specify the top, bottom, left, or right side of the toolbar. The Row and Column parameters specify a number on the existing rows and columns of docked toolbars at which to dock the toolbar.

You can query a toolbar to see if it is docked by using the DockStatus property. The DockStatus property will return TRUE if the toolbar is docked and FALSE if the toolbar is floating.

Dock a toolbar

This example creates a new toolbar with three buttons on it. The toolbar is then displayed and docked on the left side of the screen.

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