Is there a way to trap the CustomTaskPane’s close event when the custom task pane is closed? And will it automatically be disposed?
Locked
-
Sunday, February 08, 2009 12:48 PMModerator
Is there a way to trap the CustomTaskPane’s close event when the custom task pane is closed? And will it automatically be disposed?
Please remember to mark the replies as answers if they help and unmark them if they provide no help.- Edited by Ji.ZhouModerator Saturday, February 14, 2009 1:25 AM
All Replies
-
Sunday, February 08, 2009 12:48 PMModerator
You can handle the VisibleChanged event to determine when the end user closes the custom task pane. However please note that Office applications prevent you from changing some custom task pane properties in the VisibleChanged event handler, including Width, Height, Visible, and DockPosition. If you try to modify these properties, you'll receive a COMException.
The task pane (and its resources) remains in memory until your Add-In is unloaded, or you explicitly use the ThisAddIn.CustomTaskPanes.Remove or ThisAddIn.CustomTaskPanes.RemoveAt methods. The majority of custom task panes are intended to function at the "application-level", meaning that users might show or hide the same task pane many times during a particular user session. In these cases, it makes sense to reuse the same custom task pane object. This means that the custom task pane object can be reused each time the user shows the task pane. If you do not want the custom task pane object to remain in memory, you can use the Remove or RemoveAt methods accordingly.
One case you might want to do this in is Outlook, where you might display a unique custom task pane for each item (e-mail, contact, etc.) the user has open. In this case, you'll probably want to explicitly clean up each task pane when the user closes the corresponding item, in order to use the resources efficiently.
See Walkthrough: Displaying Custom Task Panes with E-Mail Messages in Outlook for an example of this. Relative link: Walkthrough: Displaying Custom Task Panes with E-Mail Messages in Outlook http://msdn.microsoft.com/en-us/library/bb296010.aspx
(Related forum thread, http://social.msdn.microsoft.com/forums/en-US/vsto/thread/be8109b6-b56e-4153-acb6-f97f47dbbdff/ )
For more FAQ about Visual Studio Tools for Office, please see Visual Studio Tools for Office FAQ
Please remember to mark the replies as answers if they help and unmark them if they provide no help.- Marked As Answer by Ji.ZhouModerator Wednesday, February 11, 2009 12:55 PM

