Accessing ADXForm instance

Add-in Express™ Support Service
That's what is more important than anything else

Accessing ADXForm instance
 
Chris McA




Posts: 58
Joined: 2014-01-21
Hello,

I am creating a form inside Outlook as follows;


this.myPanel = new AddinExpress.OL.ADXOlFormsCollectionItem(this.components);
myPanel.Cached = AddinExpress.OL.ADXOlCachingStrategy.OneInstanceForAllFolders;
myPanel.FormClassName = typeof(MyPanel).FullName;

formsManager.Items.Add(myPanel);


My question is; is there any way for me to access the instance of this form that ADX creates? I know it will wait until the region is actually shown before instantiating the form, so is there an event I should hook into? And if I hook into this event, am I actually able to access the instance of "MyPanel"?

The reason I ask is because I want to inject some dependencies into the form instance. I'm happy enough that I will only be able to do this via properties because ADX is going to do the creation using the default constructor.

Thanks for your help,
Chris
Posted 28 Feb, 2014 05:42:44 Top
Andrei Smolin


Add-in Express team


Posts: 14137
Joined: 2006-05-11
Hello Chris,

You need to use the ADXOlForm.ADXBeforeFormShow or ADXOlForm.ADXAfterFormShow event.

Regards from Belarus (GMT+3),

Andrei Smolin
Add-in Express Team Leader
Posted 28 Feb, 2014 07:20:46 Top
Chris McA




Posts: 58
Joined: 2014-01-21
Hi Andrei,

This may be a stupid question, but because ADX creates the forms internally, then how can I subscribe to these events from any other context besides inside the form's constructor (or "Loaded" event)?

Note: the dependencies I want to pass into the form are created during the AddinInitialize event.

Thanks,
Chris
Posted 28 Feb, 2014 09:45:06 Top
Andrei Smolin


Add-in Express team


Posts: 14137
Joined: 2006-05-11
Chris McA writes:
This may be a stupid question, but because ADX creates the forms internally, then how can I subscribe to these events from any other context besides inside the form's constructor (or "Loaded" event)?


See the designer window of the form.

Chris McA writes:
Note: the dependencies I want to pass into the form are created during the AddinInitialize event.


Consider doing the same from another side: let the form itself load whatever is required using some event.

Regards from Belarus (GMT+3),

Andrei Smolin
Add-in Express Team Leader
Posted 28 Feb, 2014 10:20:08 Top
Chris McA




Posts: 58
Joined: 2014-01-21
My issue with that approach is that the dependencies in question actually need to be shared amongst a few different forms - which is why I wanted to create them at some level outside the scope of the form's themselves.

I can get around this by setting the dependencies on a static member of a class that the forms can access, but this just feels wrong.

Does a form have any knowledge of its parent context at all, or is it totally isolated?

Cheers,
Chris
Posted 28 Feb, 2014 14:48:08 Top
Andrei Smolin


Add-in Express team


Posts: 14137
Joined: 2006-05-11
Chris,

Chris McA writes:
Does a form have any knowledge of its parent context at all, or is it totally isolated?


See the AddinModule, Item, FormsManager, ExplorerObj and InspectorObj properties of the ADXOlForm class.

You can create a property on the add-in module: when being accessed for the first time, the property could create the resource(s) in question and return the created and initialized resource in subsequent calls. What do you think?

Regards from Belarus (GMT+3),

Andrei Smolin
Add-in Express Team Leader
Posted 03 Mar, 2014 01:58:10 Top
Chris McA




Posts: 58
Joined: 2014-01-21
Perfect - that solves my problem Andrei.

Thanks for the help in pointing me towards the AddinModule property.

Regards,
Chris
Posted 03 Mar, 2014 06:34:10 Top
Andrei Smolin


Add-in Express team


Posts: 14137
Joined: 2006-05-11
There's another way: {project name}.AddinModule.CurrentInstance.{property or method}.

Regards from Belarus (GMT+3),

Andrei Smolin
Add-in Express Team Leader
Posted 03 Mar, 2014 07:44:02 Top