2
votes

I'm using Visual Studio 2010 and Word 2010

I've created one Winform addin in Word following this guide Create addin using VSTO in MS Word

Now I want to dock this addin to word panel. I heard that I can do that by custom task pane, I tried but can't figure how.

Is there anyone know how to do this ?

Thank you very much :) I get the pane but can't add winform into it. Finally I have to put all my winform controls into usercontrol and now it works.

2

2 Answers

3
votes

You should first create a User Control (you can do that using the designer), let's name it CustomUserControl, then add the following:

private CustomUserControl myUserControl;
private Microsoft.Office.Tools.CustomTaskPane myCustomTaskPane;

Now, in your task pane class or AddIn_Startup function, add the following:

myUserControl = new CustomUserControl();
myCustomTaskPane = Globals.ThisAddIn.CustomTaskPanes.Add(myUserControl, "TaskPane Title");

You can control the visibility of the task pane by changing the Visible property: myCustomTaskPane.Visible = true;

Note that in Word when you create such custom task pane, it will be associated with the active document. Depends on what you're trying to do, you should consider creating for each document its own instance. For more information refer to here: Managing Custom Task Panes in Multiple Application Windows

0
votes

I don't know your code. but here i paste my code. try this.

 private void ThisAddIn_Startup(object sender, System.EventArgs e)
    {
        //User Control
        uctrl_TextControl sampleControl = new uctrl_TextControl();
        Microsoft.Office.Tools.CustomTaskPane _customeTaskPane = this.CustomTaskPanes.Add(sampleControl, "Sample");
        _customeTaskPane.DockPosition = Microsoft.Office.Core.MsoCTPDockPosition.msoCTPDockPositionRight;
        _customeTaskPane.Visible = true;
        _customeTaskPane.Width = 400;
    }