In addition to using the Form Designer, you can add toolbars to form sets by using code.
To add a toolbar to a form set using code
-
In the form set's Init Event, use the SET CLASSLIB Command to specify the library containing the toolbar class, and then create a toolbar from that class in the form set.
For example, to add and display the toolbar tbrPrint
, which is based on the printing
class in the inventory
class library, add the following code to the form set's Init event:
В | ![]() |
---|---|
SET CLASSLIB TO inventory THIS.AddObject("tbrPrint","printing") THIS.tbrPrint.Show |
![]() |
---|
If the toolbar class does not define the actions of the toolbar and its buttons, you must define the actions in the event procedures associated with the toolbar and its buttons. |
You can define all aspects of a toolbar in code. For example, if you add the following code to a form set's Init event, when the form set is loaded Visual FoxPro creates and displays the toolbar defined in the code. This toolbar contains two buttons.
When chosen, these buttons change the font attributes of the form frmForm1
in the form set.
Form Set Init Event Code
Code | Comments |
---|---|
|
Adds a toolbar of the class |
Class definition code
Code | Comments |
---|---|
|
Start of the class definition: one toolbar with a command button, a separator, and another command button. |
|
Sets properties of the toolbar object. |
|
Sets properties of the controls. Notice that there are no Top or Left property settings for controls on a toolbar. Controls on a toolbar are automatically positioned in the order they are added. The FontBold property of |
|
When the toolbar is activated, the font attributes of the two command buttons are set to reflect the Bold and Italic font settings of |
|
When the user clicks |
|
When the user clicks |
|
End of the class definition. |