Share via


ToolBar Object

Creates a custom toolbar.

ToolBar

Remarks

Use the ToolBar object to create your own toolbars for your applications.

The following list describes the properties of a custom toolbar:

  • Toolbars are always on top.

  • Toolbars automatically dock when they are moved to the edge of the main Visual FoxPro window.

  • When toolbars are not docked, they have a half-height title bar.

  • When the size of a toolbar is changed, the controls are arranged to fit.

  • You can move a toolbar by clicking and dragging in any area of the toolbar that is not a control.

  • Many controls placed on the toolbar do not receive the focus when they are chosen.

  • Access keys in controls placed in a toolbar are disabled.

Although any control can be placed on a toolbar, some controls, such as a list box, may be too large to fit properly in a docked toolbar. These controls can be programmatically removed from the toolbar when the toolbar is docked and replaced with a smaller version of the same control or a different control.

For additional information about creating toolbars, see Designing Menus and Toolbars.

Example

The following example demonstrates how you can create a toolbar from the Toolbar class. Visual FoxPro rearranges the buttons when the toolbar is resized. When the ToolBar object is created, Visual FoxPro automatically places the controls from left to right in the order they are added to the class definition, ignoring the controls' Top and Left properties.

PUBLIC tbrDesktop
tbrDesktop = CREATEOBJ('myToolBar')
tbrDesktop.Show

DEFINE CLASS myToolBar AS Toolbar
   ADD OBJECT btnBold AS CommandButton
   ADD OBJECT sep1 AS Separator
   ADD OBJECT btnItalics AS CommandButton
   
   btnBold.Height = 20
   btnBold.Width = 50
   btnBold.Caption = "Bold"
   btnItalics.Height = 20
   btnItalics.Width = 50
   btnItalics.Caption = "Italic"
   btnItalics.FontBold = .F.
   
   Left = 1
   Top = 1
   Width = 25

   Caption = "Desktop Attributes"
   
   PROCEDURE Activate 
      this.btnBold.FontBold = _SCREEN.FontBold
      this.btnItalics.FontItalic = _SCREEN.FontItalic
   ENDPROC
   
   PROCEDURE btnBold.Click
      _SCREEN.FontBold = !_SCREEN.FontBold
      This.FontBold =_SCREEN.FontBold
   ENDPROC
   
   PROCEDURE btnItalics.CLICK
      _SCREEN.FontItalic = !_SCREEN.FontItalic
      This.FontItalic = _SCREEN.FontItalic
   ENDPROC
ENDDEFINE

See Also

Reference

ToolBar Object Properties, Methods, and Events

CREATE CLASS Command

CREATE FORM Command

DEFINE CLASS Command

Separator Object

Other Resources

Objects, Collections, and Classes