How To - Override a event handler implementation
This section describes how you customize a event handler in an existing form
window
The example is using the steps described in
A Simple Client Customization
as base, followed by additional steps for adding the column.
Pre-Requirements
A Simple Client Customization
getting a customized form window named frmCompany_Cust.
Note: Customize the frmCompany form window instead of
frmPersonInfo form window which is used for example above
Override a event handler implementation
- Open frmCompany using View Code.
- Go to the region Event Handlers and ensure you have the original
event handler cmdUpdatedCompany_Execute
This is the one we want to override in our customized form.
- Open frmCompany_Cust using View Design
- Open the Designer for the commandManager
- In the Available Command panel, select the cmdUpdateCompany
command and view its connected event handlers (Misc panel).
These are currently empty. The base implementation of frmCompany have
this command connected to the local event handler we found in the second
step above but the designer for frmCompany_Cust can not resolve,
showing an empty list. It will only show the local event handler for
frmCompany_Cust (which is currently none).
- Double click in the Execute attribute to generate a new
event handler named cmdUpdatedCompany_Execute and add a
MessageBox to it, showing a message of your choice.
private void cmdUpdatedCompany_Execute(object sender, Fnd.Windows.Forms.FndCommandExecuteEventArgs e)
{
MessageBox.Show("frmCompany_Cust: cmdUpdatedCompany_Execute");
}
- Mark the event handler with Override marker snippet:
Select entire event handler code -> Right mouse button context menu -> Surround width...
-> My Code Snippets -> IFS-APF -> LAA Override marker snippet and specify
the core event handler signature in it.
#region Override: private void cmdUpdatedCompany_Execute(object sender, Fnd.Windows.Forms.FndCommandExecuteEventArgs e)
private void cmdUpdatedCompany_Execute(object sender, Fnd.Windows.Forms.FndCommandExecuteEventArgs e)
{
MessageBox.Show("frmCompany_Cust: cmdUpdatedCompany_Execute");
}
#endregion
- Run IEE
- Open the Company window (Application Base
Setup\Enterprise\Company) and populate the form.
- RMB click on the window header to open its Context Menu (menuFrmMethods)
- Execute the menu option Update Company
You should first see the message from the MessageBox, followed by
showing the Update Company dialog.
This is due to having attached
another event handler to the command.
The event handlers are execute one by one, starting at the end (last
attached event handler is the first to be executed)
- To break this "chain" of event handlers from being executed one by one,
change to the following code to the customized event handler:
private void cmdUpdatedCompany_Execute(object sender, Fnd.Windows.Forms.FndCommandExecuteEventArgs e)
{
e.Handled = true;
MessageBox.Show("frmCompany_Cust: cmdUpdatedCompany_Execute");
}
- Since e.Handled is set to true, the event handler now has Overtaken core
logic. Mark the event handler with Overtake marker snippet.
#region Overtake: private void cmdUpdatedCompany_Execute(object sender, Fnd.Windows.Forms.FndCommandExecuteEventArgs e)
private void cmdUpdatedCompany_Execute(object sender, Fnd.Windows.Forms.FndCommandExecuteEventArgs e)
{
e.Handled = true;
MessageBox.Show("frmCompany_Cust: cmdUpdatedCompany_Execute");
}
#endregion
- Re-start IEE, open the same form and do the same procedure as earlier,
ending by executing the menu option Update Company
Result
The result now should be showing a message ONLY from the MessageBox.
No Update Company dialog is shown after the message.
Conclusion
Setting e.Handled = true
will break the execution chain, preventing any further event handler from
being executed.