Command Events
- Last UpdatedJun 02, 2022
- 1 minute read
The Command base class provides two events BeforeCommandExecute and CommandExecuted which enable the addin writer to write code to respond to the execution of any command object registered with the CommandManager. A command object can be retrieved from the CommandManger if its Key is known and event handlers can be attached to these events.
Command anotherCommand = commandManager.Commands["KeyOfCommand"];
anotherCommand.BeforeCommandExecute += new System.ComponentModel.CancelEventHandler(anotherCommand_BeforeCommandExecute);
anotherCommand.CommandExecuted += new EventHandler(anotherCommand_CommandExecuted);
The BeforeCommandExecute event handler is of type CancelEventHandler and is passed a CancelEventArgs object which enables the command execution to be cancelled by setting the Cancel property to true.
void anotherCommand_BeforeCommandExecute(object sender, System.ComponentModel.CancelEventArgs e)
{
e.Cancel = true;
}