Task Pane (Add-in Level)

Task panes are the interface panels typically docked to the right the the application.
MDI - single app frame, document windows inside - single task pane associated with app frame
SDI - each doc window in its own app frame - each doc window has its own task pane


Application20132010200720032002200097
ExcelSDIMDI
Show all windows in the taskbar
MDI
Show all windows in the taskbar
MDI
Windows in taskbar
MDI
Windows in taskbar
MDI
Windows in taskbar
MDI
WordSDISDI
Show all windows in the taskbar
SDI
Show all windows in the taskbar
SDI
Windows in taskbar
SDI
Windows in taskbar
SDI
Windows in taskbar
MDI
PowerPointSDISDIMDI
Show all windows in the taskbar
MDI
Windows in taskbar
MDI
Windows in taskbar
MDI
Windows in taskbar
MDI
Outlook       
InfoPath       

You can use the familiar windows forms designer to design your interface.
You can also use data binding support to bind a data sourece to the task pane controls.
All custom task panes are created contain a UserControl object (?)


Because the task pane is really just a toolbar you can access it through the CommandBars collection

Me.CommandBars("Task Pane").Position = msobarposition.msobarleft 


One difference between a custom task pane and a document level task pane is that you must explicitly set the Visible property to True to make the task pane visible.



UserControl control; 
control = new UserControl();
Microsoft.Office.Tools.CustomTaskPane pane;
pane = Microsoft.Office.Tools.CustomTaskPane.Add(control, "pane caption")

When a user closes a custom task pane, it still remains in memory until you remove it from the CustomTaskPanes collection.



The task pane is only visible in your original document.
To show document specific information you must track the currently active workbook and update the relevant information
This can be done using the Application.WindowActivate event.



When you close the document the visiblechanged event is fired and can be used to remove the task pane from the CustomTaskPanes collection.

private void ThisAddIn_Startup() 
{
   Microsoft.Office.Tools.CustomTaskPane pane = Globals.ThisAddIn.CustomTaskPanes.Add(new System.Window.Forms.UserControl(),
       "test title");
   pane.visible = true;
}


Events
DockPositionedChanged
VisibleChanged (if no active document, then remove all task panes)


mytaskpane += new System.EventHandler(TaskPane_VisibleChangedEvent) 

Application.WindowActivate activate


TaskPanes.ShowWindowsInTaskPane


Function GetTaskPaneForWindow() As Microsoft.Office.Tools.CustomTaskPane 
   For each pane in Globals.ThisAddIn.CustomTaskPanes
      If (pane.Window Is Globals.ThisAddin.Application.ActiveWindow)
         Return pane
      End If
   Next pane
End Function

Sub RemoveOrphanedTaskPanes
   For Each pane in Globals.ThisAddIn.CustomTaskPanes
      If (pane.window is nothing) and (pane.title = "") Then
         Globals.ThisAddIn.CustomTaskPanes.Remove(pane)
      End If
   Next pane
End Sub


Creating - VSTO


Add a WPF User Control
(Add > New Item)
Select "User Control (WPF) - UserControl1.xaml
Press Add


Add the following code to the startup class

private void ThisAddIn_Startup(object sender, System.EventArgs e) 
{
    System.Windows.Forms.UserControl WPF_WindowsUserControl;
    System.Windows.Forms.Integration.ElementHost _eh;

    _eh = new System.Windows.Forms.Integration.ElementHost { Dock = DockStyle.Fill, Child = new UserControl1() };

    WPF_WindowsUserControl = new System.Windows.Forms.UserControl();
    WPF_WindowsUserControl.Controls.Add(_eh);

    modSpecific._taskPane = Globals.ThisAddIn.CustomTaskPanes.Add(
        WPF_WindowsUserControl, "WJE Tools - Images");


    modSpecific._taskPane.VisibleChanged += _taskPane_VisibleChanged;
    modSpecific._taskPane.Width = 500;
    modSpecific._taskPane.DockPosition = Microsoft.Office.Core.MsoCTPDockPosition.msoCTPDockPositionRight;
    modSpecific._isTaskPaneVisible = false;

}



Creating - COM


link - https://theofficecontext.com/2013/05/21/customtaskpanes-in-a-net-shared-com-add-in/





© 2024 Better Solutions Limited. All Rights Reserved. © 2024 Better Solutions Limited TopPrevNext