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.

  1. To get started, open Visual Studio and create a new Project 2010 add-in:

    image

  2. Next, you need to add the Ribbon Designer by adding a user control to you project:

    image image

  3. 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:

    image 

  4. 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
    1. using System;
    2. using System.Collections.Generic;
    3. using System.Linq;
    4. using System.Text;
    5. using Microsoft.Office.Tools.Ribbon;
    6.  
    7.  
    8. using MSProject = Microsoft.Office.Interop.MSProject;
    9.  
    10. namespace ProjectAddIn2
    11. {
    12.  
    13.     public partial class Ribbon1
    14.     {
    15.         public static MSProject.Application Appliction;
    16.  
    17.         private void Ribbon1_Load(object sender, RibbonUIEventArgs e)
    18.         {
    19.  
    20.         }
    21.     }
    22. }

  5. The next step is to set the Application variable in the start up method of the add-in:
    Code Snippet
    1. using System;
    2. using System.Collections.Generic;
    3. using System.Linq;
    4. using System.Text;
    5. using System.Xml.Linq;
    6. using MSProject = Microsoft.Office.Interop.MSProject;
    7. using Office = Microsoft.Office.Core;
    8.  
    9. namespace ProjectAddIn2
    10. {
    11.     public partial class ThisAddIn
    12.     {
    13.         private void ThisAddIn_Startup(object sender, System.EventArgs e)
    14.         {
    15.             Ribbon1.Appliction = Application;
    16.         }
    17.  
    18.         private void ThisAddIn_Shutdown(object sender, System.EventArgs e)
    19.         {
    20.         }
    21.  
    22.         #region VSTO generated code
    23.  
    24.         /// <summary>
    25.         /// Required method for Designer support – do not modify
    26.         /// the contents of this method with the code editor.
    27.         /// </summary>
    28.         private void InternalStartup()
    29.         {
    30.             this.Startup += new System.EventHandler(ThisAddIn_Startup);
    31.             this.Shutdown += new System.EventHandler(ThisAddIn_Shutdown);
    32.         }
    33.         
    34.         #endregion
    35.     }
    36. }

  6. Last step is to add a message box that displays the name of the project:
    Code Snippet
    1. using System;
    2. using System.Collections.Generic;
    3. using System.Linq;
    4. using System.Text;
    5. using Microsoft.Office.Tools.Ribbon;
    6.  
    7.  
    8. using MSProject = Microsoft.Office.Interop.MSProject;
    9. using System.Windows.Forms;
    10.  
    11. namespace ProjectAddIn2
    12. {
    13.  
    14.     public partial class Ribbon1
    15.     {
    16.         public static MSProject.Application Appliction;
    17.  
    18.         private void Ribbon1_Load(object sender, RibbonUIEventArgs e)
    19.         {
    20.  
    21.         }
    22.  
    23.         private void button1_Click(object sender, RibbonControlEventArgs e)
    24.         {
    25.             MessageBox.Show("Active Project: " + Appliction.ActiveProject.Name);
    26.         }
    27.     }
    28. }

When you compile and run the application, you should see Project client boot and have the ribbon appear:

image

Hope this helps,

 

Chris Boyd


Comments (1)

  1. Prakhar says:

    Hi!! it says type or namespace name 'msproject' could not be found. Plz help here…