Hello everyone,
I ran into a small problem here and just can't figure it out. I'm
writing a VS .NET add-in which creates a new commandbar and populates it
with a few buttons. Each button is assigned a delegate for the Click
event, but what seems to happen is that it works the first 2 times, and
then the button does nothing after that. The delegate doesn't appear to
be called anymore. Below are a few parts of the code related to this issue.
// First we create a new commandbar
myBar = applicationObject.CommandBars.Add("some
bar",msoBarPosition.msoBarTop, false, true);
// Now lets add one button
CommandBarButton button =
(CommandBarButton)myBar.Controls.Add(MsoControlTyp e.msoControlButton, 1,
"", 1, true);
// And setup its click delegate
button.Click += new
_CommandBarButtonEvents_ClickEventHandler(ButtonCl icked);
// Here's the ButtonClicked method
public void ButtonClicked(CommandBarButton button, ref bool clicked)
{
System.Windows.Forms.MessageBox.Show("click");
}
Obviously these are all in different parts of the program, but I doubt
that's relevant. When the add-in loads, I add the commandbar to the top
and click the button 2 times. The first time I get the messagebox, the
second time I get the message box. After that, no matter how many times
I click the button, the ButtonClicked method is never called. The same
thing also happens if I put a breakpoint right on the MessageBox.Show
line. The first time this line is executed, the messagebox shows up, I
click OK, then I use F11 to get to the end of that method. Once back in
the VS, the button doesn’t work.
Any ideas on what I'm doing wrong? Thanks for any help.