Custom Task Pane query in NetOffice

Jul 10, 2013 at 3:49 AM
Hi

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

Else

    taskPane.Visible = False

End If
End Sub
Aug 7, 2013 at 5: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
Coordinator
Aug 10, 2013 at 10:59 PM
Edited Aug 10, 2013 at 11:01 PM
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="http://schemas.microsoft.com/office/2006/01/customui" onLoad="OnLoadRibbonUI">

internal IRibbonUI RibbonUI { get; private set; }

public void OnLoadRibbonUI(IRibbonUI ribbonUI)
{
  RibbonUI = ribbonUI;
}

moreover:

<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
RibbonUI.InvalidateControl("toogleButton");
}

Sebastian

EDIT: IN VB you have to use different method signatures.
this pages helps a lot to see the differents in C# and VB.NET
http://www.th-lange.com/ribbonx/ruckrufe-callbacks-in-ribbonx/