Tuesday, January 25, 2011

How to add menus in outlook menu bar using c#.net object model

Here is the code to add menubar in outlook plugin application using c#.net object model.

private Office.CommandBar menuBar;
        private Office.CommandBarPopup newMenuBar;
        private Office.CommandBarButton buttonFeedback;

And in the ThisAddIn_Startup you can write the following lines of code that will show the menu  in the menu bar.

 menuBar = this.Application.ActiveExplorer().CommandBars.ActiveMenuBar;
    newMenuBar = (Office.CommandBarPopup)menuBar.Controls.Add(
                    Office.MsoControlType.msoControlPopup, missing,
                    missing, missing, true);

 if (newMenuBar != null)
                {
                    newMenuBar.Caption = "My&Menu";
                    newMenuBar.Tag = menuTag;
 buttonFeedback = (Office.CommandBarButton)newMenuBar.Controls.Add(Office.MsoControlType.msoControlButton, missing, missing, 1, true);
                    buttonFeedback.Style = Office.MsoButtonStyle.msoButtonIconAndCaption;
                    buttonFeedback.Caption = "Customer &Feedback Option";
//Face ID will use to show the ICON in the left side of the menu.
                    buttonFeedback.FaceId = 3737;
 newMenuBar.Visible = true;
}
//You can also add event handlers for the menus.
                buttonFeedback.Click += new Microsoft.Office.Core._CommandBarButtonEvents_ClickEventHandler(buttonFeedback_Click);

No comments:

Post a Comment