Visual Studio Developer Center > Visual Studio Forums > Visual Studio Tools for Office > How to add commandbar popup to a commandbar popup
Ask a questionAsk a question
 

AnswerHow to add commandbar popup to a commandbar popup

  • Friday, November 06, 2009 10:12 AManadiks_2 Users MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     
    I am making word 2003 shared add-in. pls tell me how can i add a commandbarpopup to a commandbarpopup????

Answers

  • Friday, November 06, 2009 10:39 AMCindy MeisterMVP, ModeratorUsers MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     Answer
    Only VSTO add-ins, not Shared Add-ins, are supported in the VSTO forum. For resources for non-VSTO questions, please consult the fourm's Please Read First message.

    FWIW, a CommandBarPopup type of control has a CommandBar property. You assign this to a CommandBar object, then you can add controls to that, same as to a toolbar. You'll find a code example in the VSTO documentation on MSDN. You won't be able to use the full example, as it bases on the VSTO technology. But the part about managing CommandBars applies, see for example the procedure AddMenuBar. All you need to do is specify the correct control type. Note that the same approach applies whether you're adding a popup to the menu bar, a toolbar, or a shortcut menu.
    Cindy Meister, VSTO/Word MVP
  • Tuesday, November 10, 2009 10:30 AMBessie ZhaoMSFT, ModeratorUsers MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     Answer

    Hello,

    As code example Cindy posted, we just made a slight change with this code, mainly the Controls.Add method. In this method, define the first parameter as Office.MsoControlType.msoControlPopup. In my side, I have made a test, and finally see the third level of menu. For test, I get the New commandPopup which ID is 30037 from File menu, code like this.

            private Office.CommandBarPopup newMenuBar;
            private Office.CommandBarButton buttonOne;
            private string menuTag = "A unique tag";
            Outlook.Explorer explorer;
            Outlook.Inspectors inspectors;

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

            private void AddMenuBar()
            {
                try
                {               
                    Office.CommandBarPopup cbc = (Office.CommandBarPopup)
                        this.Application.ActiveExplorer().CommandBars.FindControl
                        (Office.MsoControlType.msoControlPopup, 30037, missing, missing);
                    Office.CommandBarPopup combarPo;
                    if (cbc != null)
                    {

                        combarPo = (Office.CommandBarPopup)cbc.Controls.
                                      Add(Office.MsoControlType.msoControlPopup, missing,missing, 1, true);                    
                        combarPo.Caption = "Button One";
                        combarPo.Tag = "c123";
                        if (combarPo != null)
                        {

                            buttonOne = (Office.CommandBarButton)combarPo.Controls.
                                         Add(Office.MsoControlType.msoControlButton, missing,missing, 1, true);
                            buttonOne.Style = Office.MsoButtonStyle.
                                msoButtonIconAndCaption;
                            buttonOne.Caption = "Button One";
                            buttonOne.FaceId = 65;
                            buttonOne.Tag = "c123";
                            //buttonOne.Click += new Office._CommandBarButtonEvents_ClickEventHandler(buttonOne_Click);

                        }
                    }
              }
                catch (Exception ex)
                {
                    System.Windows.Forms.MessageBox.Show(ex.Message);
                }
            }

    Best regards,
    Bessie


    Please remember to mark the replies as answers if they help and unmark them if they provide no help.
    Welcome to the All-In-One Code Framework! If you have any feedback, please tell us.

All Replies

  • Friday, November 06, 2009 10:39 AMCindy MeisterMVP, ModeratorUsers MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     Answer
    Only VSTO add-ins, not Shared Add-ins, are supported in the VSTO forum. For resources for non-VSTO questions, please consult the fourm's Please Read First message.

    FWIW, a CommandBarPopup type of control has a CommandBar property. You assign this to a CommandBar object, then you can add controls to that, same as to a toolbar. You'll find a code example in the VSTO documentation on MSDN. You won't be able to use the full example, as it bases on the VSTO technology. But the part about managing CommandBars applies, see for example the procedure AddMenuBar. All you need to do is specify the correct control type. Note that the same approach applies whether you're adding a popup to the menu bar, a toolbar, or a shortcut menu.
    Cindy Meister, VSTO/Word MVP
  • Friday, November 06, 2009 11:17 AManadiks_2 Users MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     
    Thanks, but as you have told we can add commandbarpopup to a commandbar, but my question was different..i want to add a commandbarpopup to a commandbarpopup object to have 3rd level of submenu. Please tell the solution?
  • Tuesday, November 10, 2009 10:30 AMBessie ZhaoMSFT, ModeratorUsers MedalsUsers MedalsUsers MedalsUsers MedalsUsers Medals
     Answer

    Hello,

    As code example Cindy posted, we just made a slight change with this code, mainly the Controls.Add method. In this method, define the first parameter as Office.MsoControlType.msoControlPopup. In my side, I have made a test, and finally see the third level of menu. For test, I get the New commandPopup which ID is 30037 from File menu, code like this.

            private Office.CommandBarPopup newMenuBar;
            private Office.CommandBarButton buttonOne;
            private string menuTag = "A unique tag";
            Outlook.Explorer explorer;
            Outlook.Inspectors inspectors;

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

            private void AddMenuBar()
            {
                try
                {               
                    Office.CommandBarPopup cbc = (Office.CommandBarPopup)
                        this.Application.ActiveExplorer().CommandBars.FindControl
                        (Office.MsoControlType.msoControlPopup, 30037, missing, missing);
                    Office.CommandBarPopup combarPo;
                    if (cbc != null)
                    {

                        combarPo = (Office.CommandBarPopup)cbc.Controls.
                                      Add(Office.MsoControlType.msoControlPopup, missing,missing, 1, true);                    
                        combarPo.Caption = "Button One";
                        combarPo.Tag = "c123";
                        if (combarPo != null)
                        {

                            buttonOne = (Office.CommandBarButton)combarPo.Controls.
                                         Add(Office.MsoControlType.msoControlButton, missing,missing, 1, true);
                            buttonOne.Style = Office.MsoButtonStyle.
                                msoButtonIconAndCaption;
                            buttonOne.Caption = "Button One";
                            buttonOne.FaceId = 65;
                            buttonOne.Tag = "c123";
                            //buttonOne.Click += new Office._CommandBarButtonEvents_ClickEventHandler(buttonOne_Click);

                        }
                    }
              }
                catch (Exception ex)
                {
                    System.Windows.Forms.MessageBox.Show(ex.Message);
                }
            }

    Best regards,
    Bessie


    Please remember to mark the replies as answers if they help and unmark them if they provide no help.
    Welcome to the All-In-One Code Framework! If you have any feedback, please tell us.