Advanced region events: how to know that the user expanded your form?
Hello folks! Through our forums and e-mail, we are frequently asked questions like this by our fellow developers: How do I know that the user expanded my Add-in Express form? In this article, I will cover the events that are raised when the region is expanded and other events that occur when the region’s state is changed.
I assume that you are already familiar with the functionality of Advanced custom task panes and Advanced Outlook form and view regions. If you haven’t read them, please read them now as they are essential for understanding. You may also want to read a related article Controlling Outlook regions’ state and forms’ size in Add-in Express 2010.
Before we are started, I would like to clarify some terms that you will come across in this article. When I say “form”, I mean an instance of ADXOlForm, ADXExcelTaskPane, ADXWordTaskPane or ADXPowerPointTaskPane. RegionState means the RegionState property of the form.
Now let me dwell on the events that occur in your form when RegionState is changed.
The Activated event is raised when the form shows up in the Normal region state and there is no other form embedded into the region.
This event also occurs when a user expands the form from the Hidden or Minimized state. If the region contains several forms, the Activated event is raised for the upper (active) form only.
Activated event and “floating” region state
The Activated event is raised when the region is in the Minimized state and the user expands the form by clicking on the form’s button.
This opens the form in such a way that it overlays part of the Outlook window near the form region. The RegionState property returns the ADXRegionState.Minimized value in this case. So, you can identify this “floating” state if you check on the RegionState property in the Activated event.
The Deactivate event is raised when the form is hidden or the user collapses the form from the Normal to Hidden or Minimized state.
Please don't try getting the RegionState property in the Deactivate event. Otherwise, you will get the “It is not possible to get the RegionState property at the moment” exception.
ADXBeforeFormShow/ ADXAfterFormShow events
If the form shows up when the region already contains some other form, then you can use the ADXBeforeFormShow or ADXAfterFormShow events or both because the Activated event is not raised in this case because the Activated event is raised when a form shown on top of all other instances in the same region.
I will remind you that the form is visible (Visible = true) when it is embedded into a region no matter if it is actually visible or not. When the form actually becomes visible, its Active property becomes true, and the Activated event is fired.
If you want to activate the form, i.e. to make it truly visible in the region, you call the Activate method in the ADXAfterformShow event.
At the very moment the form is being hidden (say, you call the Hide method), the ADXAfterFormHide event is raised.
I hope these events are sufficient to solve your tasks. If not, please let me know and I will try to find a solution.