Mixed TaskPanes, what is the best approach?

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

Mixed TaskPanes, what is the best approach?
 
OliverM


Guest


Assume my add-in uses 3 different panes, let's call them SettingsPane, Job1Pane, Job2Pane.
Further assume the add-in is targeting, Excel, Word, PowerPoint, Access and Visio as host application.

For Excel, Word and PowerPoint AdxTaskPanes can be used.
Is there something like a base class all the ADX panes are sharing, which I could use in order to avoid code doubling?


For Access and Visio only the standard MSO pane is available.
I presume implementation here is quite generic for Access, Visio and all other hosts not providing ADXTaskPanes?
Posted 23 Mar, 2018 04:21:46 Top
Andrei Smolin


Add-in Express team


Posts: 18830
Joined: 2006-05-11
Hello Oliver,

Create a UserControl, populate it with controls, add logic, and put the UserControl onto this or that pane.

Add-in Express panes aren't available for Visio and Access. According to https://msdn.microsoft.com/en-us/library/aa942839.aspx, Micosoft hasn't supplied Access and Visio with Custom Task Panes. Since there're no panes in these applications, I'd show a modal form. Non-modals usually interfere with the windowing of the host applications; typically, affected areas are tool tips, keyboard shortcuts, focus, etc.


Andrei Smolin
Add-in Express Team Leader
Posted 23 Mar, 2018 04:59:35 Top
OliverM


Guest


Hi Andrei,

I think I mixed up terms. As I learned from your docs you distinguish between advanced and standard taskpanes.
Advanced panes are available for Excel,Word, Powerpoint and Outlook.
Standard panes are available for Excel, Word, Outlook, Powerpoint, Access, Infopath, Project.
Is my understanding correct?

Add-in Express panes aren't available for Visio and Access.

This is confusing, I just created a standard pane for Access.
Posted 23 Mar, 2018 05:40:52 Top
OliverM


Guest


Some more questions regarding standard task panes.

Consider a scenario for a pane managing application settings. Such a pane should to be treated like a 'singleton'. With advanced task panes this is easy. I cancel pane creation in the pane manager by default. If a settings pane is requested, I overwrite the default cancel flag, create the pane, assign it to the calling window and show it.
If the user requests the settings pane again from another document, I hide the settings pane in doc1, assign it to doc2 and show it there again.

How can I find out the window currently hosting the standard pane?
Posted 23 Mar, 2018 07:11:56 Top
Andrei Smolin


Add-in Express team


Posts: 18830
Joined: 2006-05-11
OliverM writes:
This is confusing, I just created a standard pane for Access.


That was my fault. Add-in Express advanced panes are not available for Access and Visio; that's correct. I wrongly said that Custom Task Panes are not available for Access; they are. The *complete* list of Office applications that allows creating Custom Task Panes is given in the property editor of ADXTaskPane.SupportedApps. To see the list, open the property editor of the ADXTaskPane.TaskPanes property, create an item (it is anADXTaskPane) and check the item's SupportedApps property.

Remember that a CTP is a UserControl. I suggest creating one more UserControl to hold you controls; you place an instance of that UserControl on this or that pane.

To prevent a custom task pane from showing you use the OnTaskPaneBeforeShow event of the add-in module. In the code below uc.InfoString is defined on the UserControl that constitutes a CTP; ADXTaskPane[object] is ready to accept an object from the corresponding host application's object model; the object passed to ADXTaskPane[] must represent a window: Excel.Window, PowerPoint.PresentationWindow, Outlook.Inspector, etc.


 Private Sub RefreshTaskPaneInOutlookWindow(ByVal ExplorerOrInspector As Object)
   If Me.HostMajorVersion >= 12 Then
      Dim TaskPaneInstance As _
         AddinExpress.MSO.ADXTaskPane.ADXCustomTaskPaneInstance = _
            AdxTaskPane1.Item(ExplorerOrInspector)
      If Not TaskPaneInstance Is Nothing And TaskPaneInstance.Visible Then
         Dim uc As UserControl1 = TaskPaneInstance.Control
         If Not uc Is Nothing Then _
           uc.InfoString = GetSubject(ExplorerOrInspector)
      End If
   End If
End Sub


The example is taken from section Custom Task Panes in Office 2007-2016; see https://www.add-in-express.com/docs/net-office-custom-task-panes.php.


Andrei Smolin
Add-in Express Team Leader
Posted 23 Mar, 2018 08:18:08 Top
OliverM


Guest


Thank you for the example code. My test code now looks something like

           object myObj = null;
           switch (HostName.ToUpper())
           {
                case "MICROSOFT EXCEL":
                    myObj = AddinModule.CurrentInstance.ExcelApp.ActiveWindow;
                    break;
                case "MICROSOFT WINWORD":
                    myObj = AddinModule.CurrentInstance.WordApp.ActiveWindow;
                    break;
                // and so on..
            }
            // Hide pane currently showing in window X
            TaskPanes[0].Collection[0].Visible = false;
            // Make it show up in active window
            TaskPanes[0].Collection[0][myObj].Visible = true;


This works, the pane nicely slides out in the window where it is currently shown and smoothly slides in again in the active window. But I am still struggling to push my user control around. I tried setting the ProgId before re-showing in the active window. The code compiles but does not seem to have any effect. The pane still shows the dummy user control when it pops in the active window. I have also tried to set the user control directly but only found getters no setters.
Posted 26 Mar, 2018 06:07:30 Top
Andrei Smolin


Add-in Express team


Posts: 18830
Joined: 2006-05-11
Hello Oliver,

Try setting myUserControl.Parent = baseUserControl or using baseUserControl.Controls.Add(myUserControl).


Andrei Smolin
Add-in Express Team Leader
Posted 26 Mar, 2018 07:07:51 Top
OliverM


Guest


Sometimes, one cannot see the wood for the trees. Fiddling around with task panes, I was expecting it got to be set from there.

Thanks for the support!
Posted 26 Mar, 2018 07:39:59 Top
Andrei Smolin


Add-in Express team


Posts: 18830
Joined: 2006-05-11
You are welcome!


Andrei Smolin
Add-in Express Team Leader
Posted 26 Mar, 2018 07:41:18 Top
OliverM


Guest


I have noticed the Excel start-up time is directly related to the number of task panes created.
Creating 2 panes slows down Excel start-up roughly 3 seconds. Other host apps do not seem to be affected.
Setting the cancel flag in OnTaskPaneBeforeCreate makes Excel start-up fast again, but how can I create an instance of the pane at run time?
Posted 27 Mar, 2018 06:13:55 Top