在Project 2010中添加自定义任务窗格
2019獨角獸企業(yè)重金招聘Python工程師標準>>>
原文作者:Norm Estabrook
原文鏈接:http://blogs.msdn.com/b/vsto/archive/2010/02/02/add-a-custom-task-pane-to-project-2010-norm-estabrook.aspx
好消息, Project 2010 現(xiàn)在可以支持自定義任務窗格!壞消息,讓自定義任務窗格顯示在一個 Project 2010中并是不是那么顯而易見。總的來說還是一個好消息,因為實現(xiàn)起來比聽起來容易的多。
在這里,我會向大家演示如何利用? Visual Studio 中project 2010 或者Project 2007 的項目模板來給project 2010添加自定義任務窗格 .
?
Microsoft Office Project中任務窗格的簡單概述
在Project 2007中并不支持自定義任務窗格,而現(xiàn)在Project 2010支持它。然而,在Visual Studio 里面Project 2010 的項目模板并沒有公開顯示自定義任務窗格這一項,這也許會讓你有點泄氣。因為你知道,有了這一項,就可以通過 代碼this.CustomTaskPanes?或者?Me.CustomTaskPanes訪問CustomTaskPaneCollection?對象。
不過不用擔心,我們可以自己創(chuàng)建一個CustomTaskPaneCollection對象。具體需要什么樣的代碼來完成這個則由你的項目綁定的.Net Framework 的版本來決定。
那么現(xiàn)在,在你的工程中添加一個用戶控件User Control。這個控件給你的自定義任務窗格提供了界面設計。接下來,明確你要綁定的.Net Framework的版本。如果你創(chuàng)建的是一個新的Project 2010的項目,那么唯一的選擇就是綁定 .NET?Framework 4。盡管如此,確認版本一下也沒什么大礙。這里有一片很有用的文章,主要就是介紹關于這個內容。How to: Target a Specific .NET Framework Version or Profile.
等你做完了所有上面的步驟,把下面的代碼添加到項目中。
對于綁定 .NET?Framework 4的項目:
?
[VB]
????Private myUserControl1 As MyUserControl
??? Private myCustomTaskPane As Microsoft.Office.Tools.CustomTaskPane
??? Private myCustomTaskPaneCollection As Microsoft.Office.Tools.CustomTaskPaneCollection
?
????Private?Sub?ThisAddIn_Startup() Handles Me.Startup
??????? myUserControl1 = New MyUserControl
??????? myCustomTaskPaneCollection = Globals.Factory.CreateCustomTaskPaneCollection _
??????? (Nothing, Nothing, "CustomTaskPanes", "CustomTaskPanes", Me)
??????? myCustomTaskPane = myCustomTaskPaneCollection.Add(myUserControl1, "My Task Pane")
??????? myCustomTaskPane.Visible = True
??? End Sub
?
????Private?Sub?ThisAddIn_Shutdown() Handles Me.Shutdown
??????? myCustomTaskPaneCollection.Dispose()
??? End Sub
[C#]
????private MyUserControl myUserControl1;
??? private Microsoft.Office.Tools.CustomTaskPane myCustomTaskPane;
??? private Microsoft.Office.Tools.CustomTaskPaneCollection myCustomTaskPaneCollection;
?
??? private void ThisAddIn_Startup(object sender, System.EventArgs e)
??? {
??????? myUserControl1 = new MyUserControl();
??????? myCustomTaskPaneCollection =
??????????? Globals.Factory.CreateCustomTaskPaneCollection
??????????? (null, null, "CustomTaskPanes", "CustomTaskPanes", this);
?
??????? myCustomTaskPane = myCustomTaskPaneCollection.Add(myUserControl1, "My Task Pane");
??????? myCustomTaskPane.Visible = true;
?
??? }
?
??? private void ThisAddIn_Shutdown(object sender, System.EventArgs e)
??? {
??????? myCustomTaskPaneCollection.Dispose();
}
?
對于綁定.NET?Framework 3.5的項目:
[VB]
??? Private myUserControl1 As MyUserControl
????Private?myCustomTaskPane?As Microsoft.Office.Tools.CustomTaskPane
????Private?myCustomTaskPaneCollection?As Microsoft.Office.Tools.CustomTaskPaneCollection
?
????Private?Sub?ThisAddIn_Startup() Handles Me.Startup
??????? myUserControl1 = New MyUserControl
??????? myCustomTaskPaneCollection = New Microsoft.Office.Tools.CustomTaskPaneCollection _
??????????? (Me.ItemProvider, Me.HostContext, "MyTaskPane", Me, "MyTaskPane")
??????? myCustomTaskPane = myCustomTaskPaneCollection.Add(myUserControl1, "My Task Pane")
??????? myCustomTaskPane.Visible = True
??? End Sub
?
????Private?Sub?ThisAddIn_Shutdown() Handles Me.Shutdown
??????? myCustomTaskPaneCollection.Dispose()
??? End Sub
[C#]
??? private MyUserControl myUserControl1;
??? private Microsoft.Office.Tools.CustomTaskPane myCustomTaskPane;
??? private Microsoft.Office.Tools.CustomTaskPaneCollection myCustomTaskPaneCollection;
?
??? private void ThisAddIn_Startup(object sender, System.EventArgs e)
??? {
??????? myUserControl1 = new MyUserControl();
??????? myCustomTaskPaneCollection = new Microsoft.Office.Tools.CustomTaskPaneCollection
??????????????? (this.ItemProvider, this.HostContext, "MyTaskPane", this, "MyTaskPane");
?
??????? myCustomTaskPane = myCustomTaskPaneCollection.Add(myUserControl1, "My Task Pane");
??????? myCustomTaskPane.Visible = true;
??? }
?
??? private void ThisAddIn_Shutdown(object sender, System.EventArgs e)
??? {
??????? myCustomTaskPaneCollection.Dispose();
}
想用Project 2007?沒問題,檢查一下這里。
所以,如果你正在使用? Visual Studio 2008,并且你沒有 Project 2010項目模板,也沒有問題。 Project 2010 可以承載Project 2007的外接程序。你需要做的只是去配置一下你的項目的設置,讓 Project 2010可以運行起來。可執(zhí)行文件的名字是WINPROJ.exe。
在解決方案瀏覽器中右擊你的項目,選擇屬性,選擇調試界面。下面的截屏顯示了我的操作:
?
轉載于:https://my.oschina.net/fenglinwansu/blog/2253395
總結
以上是生活随笔為你收集整理的在Project 2010中添加自定义任务窗格的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 运算符重载:即为函数
- 下一篇: 动手使用ABAP Channel开发一些