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

Loading a Word Custom Task Pane via a check box in the ribbon UI - using VB

Apr 23, 2013 at 11:50 AM
Edited Apr 26, 2013 at 12:22 AM

I want to be able to load (ie make visual) a custom task pane via a check box. The following is the code that I have added. I added a simple 150 x 150 usercontrol.

I cannot seem to link up the checkbox1state with the custom task pane (user control). I want to be able to dock the pane both left and right and float it.

I also want to added the following functionality:
  • If the user closes the pane the checkbox is unchecked
  • When the user rechecks the chextbox, the pane is displayed where the user last had it
Any assistance would be greatly appreciated.

In the RibbonUI.xml I have added the xml statement
<checkBox id="CheckBox1" label="Picture Table Editor Pane" onAction="CheckBox1_Pressed"/>

And I have added the following lines of code to Addin.vb (I added the message boxes as a means to test if the ribbon check box was working - so this can be removed)
Dim myUserControl As New UserControl1()

Dim CheckBox1State As Boolean

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

    myUserControl.Dock = MsoCTPDockPosition.msoCTPDockPositionLeft
    myUserControl.Width = 300

    If CheckBox1State Then
        MessageBox.Show("Checkbox is Checked")
        myUserControl.Visible = True
        MessageBox.Show("Checkbox is Unchecked")
        myUserControl.Visible = False
    End If

End Sub
Apr 26, 2013 at 2:05 AM

If anyone could assist with the above that would be great. Thanks.
Apr 27, 2013 at 2:54 AM
I have been going through the custom task pane example in VB. I know to use the following code. How do I link this with the checkbox in the ribbon UI to change the visibility state, ie link the checkbox toggle status with the visibility status of the custom task pane

Adding the ICustomTaskPaneConsumer to the Implements

And use the CTPFactoryAvailable sub to create the custom task pane.

Public Sub CTPFactoryAvailable(ByVal CTPFactoryInst As Object) Implements NetOffice.OfficeApi.ICustomTaskPaneConsumer.CTPFactoryAvailable
        Dim ctpFactory As Office.ICTPFactory = New Office.ICTPFactory(_wordApplication, CTPFactoryInst)
        Dim taskPane As Office._CustomTaskPane = ctpFactory.CreateCTP(GetType(Addin).Assembly.GetName().Name + ".SampleControl", "NetOffice Sample Pane(VB4)", Type.Missing)
        taskPane.DockPosition = MsoCTPDockPosition.msoCTPDockPositionLeft
        taskPane.Width = 300
        taskPane.Visible = True
        _sampleControl = taskPane.ContentControl
End Sub
Aug 7, 2013 at 6:38 PM
tried an answer here, hope it helps!