Visual Studio Development Bookmark and Share   
 index > Visual Studio Tools for Office > How to add controls to the standard toolbar - new dropdown list?
 

How to add controls to the standard toolbar - new dropdown list?

Hi,
I am trying to add a menu item into the standard toolbar. I was ablw to add it directly. But I want to add them under the drop downlist of new (when we click the down arrow after new, we are getting a list of menus. there I want to add.

can anyone give me a sample code for this.

Thanks
Madhavi.Nekkanti  Wednesday, October 14, 2009 12:47 PM

Hello Madhavi,

In Outlook 2003, New button in toolbar is added/removed by click dropdown arrow of the toolbar. It originally comes from the submenu New of File Menu. So we just add a menu item to New submenu item. In this thread, it introducts how to add an item to menu. Here, I have made a slight changes with the code posted by Norm in above link,

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

                 if (cbc != null)
                {

                    buttonOne = (Office.CommandBarButton)cbc.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);
            }
        }

Now, by launching Outlook 2003, you will see this new button in the toolbar and File menu->New.

If you have any further question, please feel free to let us know.

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.
Bessie Zhao  Friday, October 16, 2009 6:50 AM
Which Office application? And which version of that application? And which version of VSTO are you using?
Cindy Meister, VSTO/Word MVP
Cindy Meister  Wednesday, October 14, 2009 1:08 PM
Outlook 2003. I am using visual studio 2008
Madhavi.Nekkanti  Wednesday, October 14, 2009 1:29 PM

Hello Madhavi,

In Outlook 2003, New button in toolbar is added/removed by click dropdown arrow of the toolbar. It originally comes from the submenu New of File Menu. So we just add a menu item to New submenu item. In this thread, it introducts how to add an item to menu. Here, I have made a slight changes with the code posted by Norm in above link,

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

                 if (cbc != null)
                {

                    buttonOne = (Office.CommandBarButton)cbc.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);
            }
        }

Now, by launching Outlook 2003, you will see this new button in the toolbar and File menu->New.

If you have any further question, please feel free to let us know.

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.
Bessie Zhao  Friday, October 16, 2009 6:50 AM
Hi Bessie,
Thank you very much. This is helpful to me.

I am trying to provide my own functionality when the use clicks just "New". not the popup.

Office.

CommandBarPopup cbc = (Office.CommandBarPopup)

 

this.Application.ActiveExplorer().CommandBars.FindControl

(Office.

MsoControlType.msoControlPopup, 30037, missing, missing);

 

cbc.OnAction =

"newMenu_Click";

But I am getting errror as "Member not found"

Can you please help me undertsand what is wrong with this. How to resolve the problem?


I tried with both these alternatives for newMenu_Click

//Error with this also

 

public void newMenu_Click(Microsoft.Office.Core.CommandBarPopup Ctrl, ref bool CancelDefault)

{

MessageBox.Show("new button clicked............");}

//Error with this also

public void newMenu_Click()

{

MessageBox.Show("new button clicked............");}

 



Thanks in advance

Madhavi.Nekkanti  Friday, October 16, 2009 11:16 AM

For this error, you could get an answer from this thread near the end.In OnAction Property page, it says, this property is used to get/set the name of a Visual Basic property that will run when the user clicks or changes the value.

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.
Bessie Zhao  Monday, October 19, 2009 2:35 AM

How can I provide a vb procedure name while I am developing the project in c#. I saw the mentioned thread before also. But I didnt understand how to achieve this.

Madhavi.Nekkanti  17 minutes ago

You can use google to search for other answers

Custom Search

More Threads

• BeginUpdate/EndUpdate on excel list object
• MS Word Application
• Save word document content to database problem
• Outlook 2007 MAPI Replacement
• DataTables to Excel
• Error: Office Document Customization in not available Excel 2003
• problem with VSTO2005SE install
• HOWTO: AddIn Deployment with Shim for Framework1.1 & Framework2.0
• Changing Headers And Footers With VSTO
• Events on shared calendar are not catched ?