Subscribing to events of .Net controls in toolbars

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

Subscribing to events of .Net controls in toolbars
Subscribing to events of .Net controls in toolbars 
Mike M.




Posts: 31
Joined: 2006-11-13
Hi

I am trying to use a .Net combobox on toolbars in explorer and inspector windows in outlook.

From the documentation of Add-in Express 2007 Extensions, I can see that I am supposed to use ActiveInstance of the advanced toolbar control. This active instance is apparently a clone of the control that was added at design time, but the documentation is VERY vague about this, so I have a few questions:

1) When should I hook up to say, the SelectedIndexChanged event of combobox displayed in a toolbar in an Outlook explorer window.

2) Should it be events of the active instance or the original control that I subscribe to? In the adx sample, I can see that you hook up to a linklabel.click at design time, which would be the orignal control instance right?

My combo however, is embedded in a usercontrol, and it is the user control that is added to the toolbar. The usercontrol does not expose the combobox event, but I guess I could easily dot this, if I must subscribe to events at design time.

3) When are the clones created, and what are their lifetimes?

4) Is a new clone of a .Net control created for each toolbar in each window?

5) Should I unsubscribe from the events when an explorer og inspector window closes.

Please consider extending the documentation about the use of the ActiveInstance property. As far as I can see this is a very important property to know about, but it is only described briefly in the Advanced Understanding section of the doc.

best regards Mike
Posted 02 Feb, 2007 04:36:21 Top
Mike M.




Posts: 31
Joined: 2006-11-13
I have now done the following test:

1. I have a usercontrol containing a combobox.
2. The usercontrol is displayed in a toolbar in an outlook explorer window.
3. I wish to subscribe to the SelectedIndexChanged event of the combobox inside the usercontrol.

If I make the Combobox available in a getter property on the user control and subscribes to its SelectedIndexChanged evetn, the eventhandler is never called. If do the subscription immediately after the call to InitializeComponent() in the constructor of my add in module (which i believe is before the clone on the toolbar has been created.)

If I instead create a new event on the usercontrol that is raised when the embedded ComboBox raises SelectedIndexChanged, then my event handler is called. Again I subscribed to the new usercontrol event immediately after the InitializeComponent() call in the ctor of the add-in module. So in this case the event subscriptions on the user control are cloned.

What is recommended approach to handling events of nested controls in usercontrols that er used on toolbars ?

Posted 02 Feb, 2007 05:42:17 Top
Dmitry Kostochko


Add-in Express team


Posts: 2875
Joined: 2004-04-05
Hi Mike,

1) When should I hook up to say, the SelectedIndexChanged event of combobox displayed in a toolbar in an Outlook explorer window.


You can set all event handlers at design-time.

2) Should it be events of the active instance or the original control that I subscribe to? In the adx sample, I can see that you hook up to a linklabel.click at design time, which would be the orignal control instance right?


Yes, right, you need to set all event handlers at design-time.

3) When are the clones created, and what are their lifetimes?


It depends on the host application. E.g. with Outlook inspector window the control will be created when inspector window shows up (just before the InspectorActivate event) and will be destroyed when the inspector window closes (just after the InspectorClose event).

4) Is a new clone of a .Net control created for each toolbar in each window?


And again it depends on the host application. For Outlook and Word the answer is true. For Excel and PowerPoint a control will be created only once.

5) Should I unsubscribe from the events when an explorer og inspector window closes.


It is not necessary.

What is recommended approach to handling events of nested controls in usercontrols that er used on toolbars ?


You can add all event handlers at design-time.

If you have other questions feel free to ask me.

P.S. Note that we take up your forum requests in the order we receive them.
Besides, it may take us some time to investigate your issue. Please be sure we will let you know as soon as the best possible solution is found.


Posted 02 Feb, 2007 07:08:43 Top