2013-10-21 156 views
1

我使用Visual Studio 2010和Word 2010中添加WinForm的插件自定義任務窗格在Word

我已經創建了一個WinForm的插件在Word本指南 Create addin using VSTO in MS Word

現在我想停靠此以下插入到字面板。我聽說我可以通過自定義任務窗格來做到這一點,我試過但不知道如何。

有沒有人知道如何做到這一點?

非常感謝你:)我得到窗格,但不能將winform添加到它。最後,我必須把我所有的winform控件放到用戶控件中,然後才能正常工作。

回答

1

,必須先創建一個用戶控件(你可以做到這一點使用設計),讓我們將其命名爲CustomUserControl,然後添加以下:

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

現在,在任務窗格中類或AddIn_Startup功能,添加以下內容:

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

您可以通過更改Visible屬性控制任務窗格中的可見性:myCustomTaskPane.Visible = true;

請注意,在Word中創建此類自定義任務窗格時,它將與活動文檔關聯。取決於你想要做什麼,你應該考慮爲每個文檔創建自己的實例。 欲瞭解更多信息,請參考此處: Managing Custom Task Panes in Multiple Application Windows

+0

感謝您的回答:)它有幫助 – user2902584

0

我不知道你的代碼。但在這裏我粘貼我的代碼。嘗試這個。

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; 
    } 
+0

感謝您的快速回答,dock窗格確實出現了,我怎樣才能將我的winform添加到它? – user2902584

+0

第一行我實例化了winform用戶控件。將該對象添加到custome任務窗格。 –

相關問題