Click here to Skip to main content
12,690,140 members (30,987 online)


AnswerRe: C# Monitoring Project Pin
Wayne Gaylard31-Jul-12 0:10
mentorWayne Gaylard31-Jul-12 0:10 
AnswerRe: C# Monitoring Project Pin
Pete O'Hanlon31-Jul-12 0:16
protectorPete O'Hanlon31-Jul-12 0:16 
AnswerRe: C# Monitoring Project Pin
OriginalGriff31-Jul-12 23:27
mvpOriginalGriff31-Jul-12 23:27 
GeneralClickEventHandler fireing twice !! [SOLVED] Pin
Riadh1s30-Jul-12 23:14
memberRiadh1s30-Jul-12 23:14 
I'm having a serious problem and I'm stuck with for three days now. I'm currently developping an add-in for Outlook 2007, and I'm having a toolbar and a menu bar.
The problem is, and I really don't understand why, _CommandBarButtonEvents_ClickEventHandler fires events twice, and sometimes even four times !!

Here is my function where I create the CommandButton elements which will be inserted in menu and tool bars :

public void creationBouton_SubMenu(string labelBouton, string nomRessource, Stream imgageStream, short fromToolBarOrManuBar, ref Office.CommandBarButton bouton)
            Assembly ThisAssembly = Assembly.GetExecutingAssembly();
            bouton = null;
            if (fromToolBarOrManuBar == fromToolBar)
                bouton = (Office.CommandBarButton)newToolBar.Controls.Add(MsoControlType.msoControlButton, missing, missing, missing, false);
                bouton.Style = Office.MsoButtonStyle.msoButtonIconAndCaptionBelow;
            else if (fromToolBarOrManuBar == fromMenuBar)
                bouton = (Office.CommandBarButton)_objNewMenuBar.Controls.Add(MsoControlType.msoControlButton, missing, missing, 1, true);
                bouton.Style = Office.MsoButtonStyle.msoButtonIconAndCaption;
            bouton.Caption = labelBouton;
            Random random = new Random(10000);
            bouton.Tag = "Basic Tag" + random.Next(1000).ToString();    //just en ensure having different tags for each commandbutton
            imgageStream = ThisAssembly.GetManifestResourceStream(namespaceCourant + ".Resources." + nomRessource);
            bouton.Picture = MyHost.GettIPictureDispFromPicture(Image.FromStream(imgageStream));

            //assign the action to the buttom
            bouton.Click += new Office._CommandBarButtonEvents_ClickEventHandler(Lancement_Formualire_Event);

            bouton.Visible = true;

And here where I call this method :

private void AddMenubar()
            Stream imgageStream = null; //intialisation
                //Define the existent Menu Bar
                _objMenuBar = this.Application.ActiveExplorer().CommandBars.ActiveMenuBar;
                //Define the new Menu Bar into the old menu bar
                _objNewMenuBar = (Office.CommandBarPopup)_objMenuBar.Controls.Add(Office.MsoControlType.msoControlPopup, missing, missing, missing, false);
                if (_objNewMenuBar != null)
                    _objNewMenuBar.Caption = "RPVApp";
                    _objNewMenuBar.Tag = "RPVApp tag";


                    //Creation of submenu items
                    creationBouton_SubMenu("Nouveau message civil", "message.png", imgageStream, fromMenuBar, ref bt_NouveauMessageCivil);
                    creationBouton_SubMenu("Réception messages", "message2.png", imgageStream, fromMenuBar, ref bt_ReceptionMessage);


And finally here the call to create the tool bar items :

Stream imgageStream = null; //intialisation
            if (newToolBar == null)
                Office.CommandBars cmdBars = this.Application.ActiveExplorer().CommandBars;
                newToolBar = cmdBars.Add("RPVApp_Toolbar", Office.MsoBarPosition.msoBarTop, false, true);
                //bouton Nouveau message civil
                creationBouton_SubMenu("Nouveau message civil", "message.png", imgageStream, 1, ref bt_NouveauMessageCivil);
                //bouton réceptoin messages
                creationBouton_SubMenu("Réception messages", "message2.png", imgageStream, 1, ref bt_ReceptionMessage);
                //bouton dossiers en cours

                newToolBar.Visible = true;
            catch (Exception ex)

Thank you in advance for your help !

modified 31-Jul-12 6:25am.

AnswerRe: ClickEventHandler fireing twice !! Pin
Pete O'Hanlon30-Jul-12 23:25
protectorPete O'Hanlon30-Jul-12 23:25 
GeneralRe: ClickEventHandler fireing twice !! Pin
Riadh1s30-Jul-12 23:42
memberRiadh1s30-Jul-12 23:42 
GeneralRe: ClickEventHandler fireing twice !! Pin
Pete O'Hanlon31-Jul-12 0:00
protectorPete O'Hanlon31-Jul-12 0:00 
GeneralRe: ClickEventHandler fireing twice !! Pin
Riadh1s31-Jul-12 0:24
memberRiadh1s31-Jul-12 0:24 
GeneralRe: ClickEventHandler fireing twice !! Pin
Pete O'Hanlon31-Jul-12 1:03
protectorPete O'Hanlon31-Jul-12 1:03 
GeneralRe: ClickEventHandler fireing twice !! Pin
Riadh1s31-Jul-12 1:24
memberRiadh1s31-Jul-12 1:24 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

Advertise | Privacy | Mobile
Web02 | 2.8.170117.1 | Last Updated 16 Jan 2017
Copyright © CodeProject, 1999-2017
All Rights Reserved. Terms of Service
Layout: fixed | fluid