Add a new button in Outlook 2010 using c# addin project


Start a ‘Add in new project’ in Visual studio 2010 .By default ThisAddIn_Startup,ThisAddIn_Shutdown will be there .Add the below code in the ThisAddIn_Startup event. 

 private Office.CommandBar OLmenuBar;
        private Office.CommandBarPopup OnMenuBar;
        private Office.CommandBarButton OutLookButton;

               private void ThisAddIn_Startup(object sender, System.EventArgs e)
        {
            AddMenuBar();
        }


private void AddMenuBar()

        {
try
              {

                OLmenuBar = this.Application.ActiveExplorer().CommandBars.ActiveMenuBar;

                OnMenuBar = (Office.CommandBarPopup)OLmenuBar.Controls.Add(

                    Office.MsoControlType.msoControlPopup, missing,

                    missing, missing, true);

                if (OnMenuBar != null)
{

                    OnMenuBar.Caption = "My Menu";

                    OutLookButton = (Office.CommandBarButton)OnMenuBar.Controls.

                    Add(Office.MsoControlType.msoControlButton, missing,

                        missing, 1, true);

                    OutLookButton.Style = Office.MsoButtonStyle.

                        msoButtonIconAndCaption;

                    OutLookButton.Caption = "Button One";

                    OutLookButton.FaceId = 65;

                    OutLookButton.Tag = "c123";

                    OutLookButton.Click += new

                        Office._CommandBarButtonEvents_ClickEventHandler(delegate(Office.CommandBarButton c, ref bool c1)

                            {                 
                                                   //Event here
                            });

                    OnMenuBar.Visible = true;

                  }

            }

            catch (Exception ex)

            {

                System.Windows.Forms.MessageBox.Show(ex.Message);

            }

        }

 

No comments:

Post a Comment