Partager 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

ToolBar Object Properties, Methods and Events | CREATE CLASS | CREATE FORM | DEFINE CLASS | Separator Object