Good news! Project 2010 supports custom task panes! Bad News! Getting one to appear in a Project 2010 is not so obvious. Good News! It’s a lot easier than I make it sound.
In this post, I’ll show you how to add a custom task pane to Project 2010 by using a Project 2010 or Project 2007 project template in Visual Studio.
Project 2007 does not support custom task panes. Project 2010 does support custom task panes. The thing that might throw you off is that the Project 2010 project template in Visual Studio does not expose that cool CustomTaskPanes field. You know, that field that enables you to access a CustomTaskPaneCollection object by typing this.CustomTaskPanes or Me.CustomTaskPanes?
No worries. We can just create a CustomTaskPaneCollection object ourselves. The exact code that you use to accomplish that depends on the .NET Framework version that your project targets.
For now, add a User Control item to your project. This provides the design surface for your custom task pane. Next, identify which version of the .NET Framework you are targeting. If you created a brand new Project 2010 project, then odds favor that your project targets the .NET Framework 4. However, it never hurts to check. Here is a helpful topic that shows you how to examine that little piece of info - How to: Target a Specific .NET Framework Version or Profile.
After you do all of that, add this code:
[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(); }
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
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(); }
So what if you are using Visual Studio 2008 and you do not have a Project 2010 project template? No problem. Project 2010 can host a Project 2007 add-in. All you have to do is configure your project settings to open the Project 2010 executable on start up. The name of that executable file is WINPROJ.exe.
Right click your project node in Solution Explorer, click Properties, click the the Debug tab, and point away! Here is a screenshot of how I did it.
Norm E.