Microsoft Office Tutorials and References
In Depth Information
Creating a Commandbar for Microsoft Project
Let's see an example of how to create a Commandbar menu for Microsoft Project by
using VSTO objects.
Open Visual Studio 2008, to create a new Project solution. Write the following code
in the ThisAddIn.cs file:
// Office commandbar initializing
Office.CommandBar PacktCmdBar;
// Office commandbarbutton initializing
Office.CommandBarButton PacktButton;
private void ThisAddIn_Startup(object sender, System.EventArgs e)
// Commandbar object indexing
if (PacktCmdBar == null)
// Add a commandbar named ‘Export Data'
PacktCmdBar = Application.CommandBars.Add("Export Data",
1, missing, true);
// Adding button to the commandbar and event handler.
PacktButton = (Office.CommandBarButton)PacktCmdBar.Controls.
Add(1, missing, missing, missing, missing);
// Set the button style property
PacktButton.Style = Office.MsoButtonStyle.
// Set the caption for the Button
PacktButton.Caption = "Export Data";
// Set the tag for the Button
PacktButton.Tag = "Export Data Tag";
// Click event for the Button in the commandbar
PacktButton.Click += new Office.
// Set the commandbar to visible
PacktCmdBar.Visible = true;
// Click event for the button in the commandbar
private void ButtonClick(Office.CommandBarButton PacktCtrl,
ref bool cancel)
// Message to be displayed
MessageBox.Show("Set your operation here!");
Search JabSto ::

Custom Search