Compartir a través de


Coordinate Menu Items and Toolbar Buttons Sample

File: ...\Samples\Solution\Menus\Toolmenu.scx

This sample illustrates coordinating menu items and toolbar buttons that provide the same functionality.

Sometimes you'll want to make particular functionality accessible from both menu items and toolbar buttons. For example, in Visual FoxPro you can save a file by choosing the Save toolbar button or by choosing Save from the File menu.

The three components to this sample are as follows:

Component

Description

Toolmenu.scx

the form

tbrBackColor in Solution.vcx

the toolbar

Toolmenu.mnx

the menu

In the Init event of the form, a toolbar object is created whose object reference is a property on the form, oToolbar.

SET CLASSLIB TO ..\solution
This.oToolbar = CREATEOBJECT('tbrbackcolor')

* Position the toolbar and show it
THIS.oToolbar.Left = THIS.Left + 10
THIS.oToolbar.Top = THIS.Top - 50
THIS.oToolbar.Visible = .T.

* Push the current menu on the stack so it can be 
* restored in the Destroy event of the form.
PUSH MENU _MSYSMENU

* Run the menu
DO toolmenu.mpr

Rather than coding duplicate functionality in the toolbar and the menu, updating it both places if changes are required, the code associated with the menu items calls the code associated with the toolbar buttons. For example, the following command is associated with the first menu item:

_VFP.ActiveForm.oToolbar.cmdRed.click

The SKIP FOR clause of the menu items causes them to be disabled when the associated toolbar button is disabled. For example, the following expression is associated with the SKIP FOR clause of the first menu item:

!_VFP.ActiveForm.oToolbar.cmdRed.Enabled

See Also

Tasks

Solution Samples

Reference

Item Locator Foundation Class

Format Toolbar Foundation Class

Visual FoxPro Foundation Classes A-Z

Other Resources

Menus and Toolbars Solution Samples