Microsoft Office Tutorials and References
In Depth Information
Menus in Outlook
Remember that menus and CommandBars are not VSTO features, but
are in the Microsoft.Office namespace. VSTO is making it easier to
program for the Office object model.
Let's see a demonstration of creating a custom toolbar with a button.
1. Open Visual Studio 2008, and create a new solution, as described above.
2. Next, add the reference needed to show the message box needed in
our demonstration:
// Namespace reference for message box
using System.Windows.Forms;
3. Let's write a program to create a toolbar and call it Hello World! .
// Declare the toolbar
Office.CommandBar PacktCustomToolBar;
// Declare the button
Office.CommandBarButton PacktButtonA;
private void ThisAddIn_Startup(object sender, System.EventArgs e)
{
// Verify the PacktCustomToolBar exist and add to the application
if (PacktCustomToolBar == null)
{
// Adding the commandbar to Active explorer
Office.CommandBars PacktBars = this.Application.
ActiveExplorer().CommandBars;
// Adding PacktCustomToolBar to the commandbars
PacktCustomToolBar = PacktBars.Add("NewPacktToolBar",
Office.MsoBarPosition.msoBarTop, false, true);
}
// Adding button to the custom tool bar
Office.CommandBarButton MyButton1 = (Office.
CommandBarButton)PacktCustomToolBar.Controls.Add(1,
missing, missing, missing, missing);
// Set the button style
MyButton1.Style = Office.MsoButtonStyle.msoButtonCaption;
// Set the caption and tag string
MyButton1.Caption = "PACKT BUTTON";
MyButton1.Tag = "MY BUTTON";
 
Search JabSto ::




Custom Search