Designing an APF application the developer has two button controls at hand,
cPushButton
and cCommandButton
. The cPushButton
is the simple button class that is used for a standard button implementation, i.e.
add a button to the form and hook up the click event. This page focuses on describing
how to use a cCommandButton
.
A cCommandButton
is a commander control. It is a control used
to perform an action in a window when the user interacts with it. A commander is
a control that is connected to a
command where the command
holds the logic, while the commander holds the user interface. The Command Button
is used wherever the enabled state of the button needs to be controlled. Normally
you add/create the cCommandButton
from the
Command Manager Designer directly, but it is possible to add a cCommandButton
from the Visual Studio toolbox as well.
For more detailed information on how to create and handle commands using the Command Manager Designer, see the commands page.
At least enter values for Name and Caption to have a command that is useful for a command button.
Note: Give the command a useful name. The name of the command will be reflected in event handlers as well as generated controls. A name like command<Caption> is a good name to start out with.
Figure 1. Add a new command with the Command Manager Designer.
cCommandButton
control using drag
and drop from the Visual Studio toolbox to the form.Tip: You can quickly create a new command button for a command by dragging the command with the mouse, and dropping it directly on the Buttons node.
The form having the button that uses a command, should subscribe to the command's
Inquire
and Execute
events.
The command's Execute
event is fired when the command button is
clicked. When the event is fired, the callback method will be called. The callback
method should perform the actions appropriate for the button. The Inquire
event callback methods are used by the application to set the state of commands
to reflect the state of the application. Use the Inquire
event callback
method to enable or disable a command button. This is done by changing the
Enabled
property on the Command. That property
change on the command will be reflected on the command button. Another property
that is reflected on the cCommandButton
is the Caption
property on the Command, which will set the
Text
of the button.