This project has moved and is read-only. For the latest updates, please go here.

Custom Task Pane query in NetOffice

Jul 10, 2013 at 4:49 AM

I have noticed others posting issues with using custom task panes. Can the following simply not be done in NetOffice and I need to get Visual Studio Professional.

I am trying to link the control of a checkbox in the ribbon to toggle the custom task pane visibility status. I believe I am almost there however missing a step or 2.

Assistance would be greatly appreciated thanks
Private taskPane As Office._CustomTaskPane
Private ctpFactory As Office.ICTPFactory

Private Const taskPane_PROGID As String = "Advance Tools with Custom Task Pane"

Shared _application As Word.Application

Shared myuserControl As UserControl1

Public Sub CTPFactoryAvailable(ByVal CTPFactoryInst As Object) Implements NetOffice.OfficeApi.ICustomTaskPaneConsumer.CTPFactoryAvailable
ctpFactory = CTPFactoryInst
End Sub

Public Sub CheckBox1_Pressed(ByVal control As Office.IRibbonControl, ByVal CheckBox1State As Boolean)
If CheckBox1State Then

    taskPane = ctpFactory.CreateCTP(GetType(Addin).Assembly.GetName().Name + ".UserControl1", "Picture Table Editor", Type.Missing)
    taskPane.DockPosition = MsoCTPDockPosition.msoCTPDockPositionFloating
    taskPane.Width = 300
    taskPane.Height = 420
    taskPane.Visible = True
    taskPane.DockPosition = MsoCTPDockPosition.msoCTPDockPositionLeft
    taskPane.Width = 300
    myuserControl = taskPane.ContentControl


    taskPane.Visible = False

End If
End Sub
Aug 7, 2013 at 6:31 PM
I was just having the same issue, and thanks to a post of SebastionDotNet somewhere here (of which for some reason I can't find the link any more) I solved the problem. You can do the following:
  • add a public property to your myuserControl: Public TaskPane As Office._CustomTaskPane
  • in your Public Sub CTPFactoryAvailable add a line myuserControl.TaskPane = taskPane and remove the ctpFactory.Dispose()
Then you should be able change the visibility with myuserControl.TaskPane.visible = true/false
Aug 10, 2013 at 11:59 PM
Edited Aug 11, 2013 at 12:01 AM
as first: i didnt know a way to detect the visibility of a taskpane is changed (and update checkbox or tooglebutton, i use a timer in the taskpane, not nice but helps).

what you can do is as follows:
1) create a button int the ribbon ui

public void OnAction(IRibbonControl control)
// reverse visibility
if(control.ID == "myTaskPane")
   taskPane.Visible = !taskPane.Visible;

if you want more (similar to my timer solution)
make sure you define the onload Method in the xml definition

<customUI xmlns="" onLoad="OnLoadRibbonUI">

internal IRibbonUI RibbonUI { get; private set; }

public void OnLoadRibbonUI(IRibbonUI ribbonUI)
  RibbonUI = ribbonUI;


<toggleButton id ="toogleButton" label="myLabel" size ="large" imageMso="HappyFace" onAction ="OnCheckActionToogleButton" getPressed ="GetPressedToogleButton"/>

public void OnCheckActionToogleButton(IRibbonControl control, bool check)
     taskPane.Visible = check;

public bool GetPressedToogleButton(IRibbonControl control)
    return taskPane.Visible;

moreover: if you the visibility of the pane is changed now you can use:
void Foo()
//raise GetPressedToogleButton to update the toogle button


EDIT: IN VB you have to use different method signatures.
this pages helps a lot to see the differents in C# and VB.NET