Using the Ribbon Designer with Project Client
Hey,
In this post, I will be showing how you can use the Ribbon designer in Visual Studio 2010 to create custom ribbons in Project Client 2010. To get started, you will need a copy of Visual 2010 with the Office Tools installed and Project Client 2010 installed.
To get started, open Visual Studio and create a new Project 2010 add-in:
Next, you need to add the Ribbon Designer by adding a user control to you project:
In the Ribbon Designer, add the controls you want to include on your ribbon. In my example, I am going to add a simple button, which when clicked, will display a message box with the name of the active project:
Double click on the button to view the code for the ribbon. Here, we are going to add a reference to the Project interop assembly and a static variable that will reference the application:
Code Snippet
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using Microsoft.Office.Tools.Ribbon;
- using MSProject = Microsoft.Office.Interop.MSProject;
- namespace ProjectAddIn2
- {
- public partial class Ribbon1
- {
- public static MSProject.Application Appliction;
- private void Ribbon1_Load(object sender, RibbonUIEventArgs e)
- {
- }
- }
- }
The next step is to set the Application variable in the start up method of the add-in:
Code Snippet
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using System.Xml.Linq;
- using MSProject = Microsoft.Office.Interop.MSProject;
- using Office = Microsoft.Office.Core;
- namespace ProjectAddIn2
- {
- public partial class ThisAddIn
- {
- private void ThisAddIn_Startup(object sender, System.EventArgs e)
- {
- Ribbon1.Appliction = Application;
- }
- private void ThisAddIn_Shutdown(object sender, System.EventArgs e)
- {
- }
- #region VSTO generated code
- /// <summary>
- /// Required method for Designer support - do not modify
- /// the contents of this method with the code editor.
- /// </summary>
- private void InternalStartup()
- {
- this.Startup += new System.EventHandler(ThisAddIn_Startup);
- this.Shutdown += new System.EventHandler(ThisAddIn_Shutdown);
- }
- #endregion
- }
- }
Last step is to add a message box that displays the name of the project:
Code Snippet
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using Microsoft.Office.Tools.Ribbon;
- using MSProject = Microsoft.Office.Interop.MSProject;
- using System.Windows.Forms;
- namespace ProjectAddIn2
- {
- public partial class Ribbon1
- {
- public static MSProject.Application Appliction;
- private void Ribbon1_Load(object sender, RibbonUIEventArgs e)
- {
- }
- private void button1_Click(object sender, RibbonControlEventArgs e)
- {
- MessageBox.Show("Active Project: " + Appliction.ActiveProject.Name);
- }
- }
- }
When you compile and run the application, you should see Project client boot and have the ribbon appear:
Hope this helps,
Chris Boyd
Comments
- Anonymous
June 03, 2010
Hi!! it says type or namespace name 'msproject' could not be found. Plz help here...