A
Amitai
Hi,
All I'm trying to do is trap a CommandBarButton event in Visio Add-in.
The code which creates the button is as follows:
CommandBars ourBars =
(Microsoft.Office.Core.CommandBars)applicationObject.CommandBars;
CommandBar myBar = ourBars.Add("My Tools", MsoBarPosition.msoBarTop, false,
true);
myBar.Visible = true;
CommandBarButton btn1 =
(CommandBarButton)myBar.Controls.Add(MsoControlType.msoControlButton, 1, "",
1,true);
btn1.Visible = true;
btn1.TooltipText = "do jump";
btn1.Caption = "jump";
btn1.Enabled = true;
btn1.FaceId = 3;
Now I try to attach an event handler.
I first tried:
btn1.Click+=new _CommandBarButtonEvents_ClickEventHandler(OnMyClick);
with the function:
public void OnMyClick(CommandBarButton btn, ref bool b)
{
MessageBox.Show("MyClick in action");
}
I got no exception but the event hasn't been fired either. Just nothing.
Then I tried using OnAction.
After the control creation code, I added:
btn1.OnAction = "HelloWorld";
and the function
public void HelloWorld()
{
MessageBox.Show("MyClick in action");
}
but here I got an exception on runtime once I run over the line btn.OnAction
= ...
The Exception I got had the interesting text: "unspecified error".
I tried putting Connect.HelloWorld or MyAddin.Connect.HelloWorld or
HelloWorld()
and tried defining the function static - all with no success.
So how can I trap my CommandBarButton click event in Visio add-in?
Please help
Thanks
Amitai
All I'm trying to do is trap a CommandBarButton event in Visio Add-in.
The code which creates the button is as follows:
CommandBars ourBars =
(Microsoft.Office.Core.CommandBars)applicationObject.CommandBars;
CommandBar myBar = ourBars.Add("My Tools", MsoBarPosition.msoBarTop, false,
true);
myBar.Visible = true;
CommandBarButton btn1 =
(CommandBarButton)myBar.Controls.Add(MsoControlType.msoControlButton, 1, "",
1,true);
btn1.Visible = true;
btn1.TooltipText = "do jump";
btn1.Caption = "jump";
btn1.Enabled = true;
btn1.FaceId = 3;
Now I try to attach an event handler.
I first tried:
btn1.Click+=new _CommandBarButtonEvents_ClickEventHandler(OnMyClick);
with the function:
public void OnMyClick(CommandBarButton btn, ref bool b)
{
MessageBox.Show("MyClick in action");
}
I got no exception but the event hasn't been fired either. Just nothing.
Then I tried using OnAction.
After the control creation code, I added:
btn1.OnAction = "HelloWorld";
and the function
public void HelloWorld()
{
MessageBox.Show("MyClick in action");
}
but here I got an exception on runtime once I run over the line btn.OnAction
= ...
The Exception I got had the interesting text: "unspecified error".
I tried putting Connect.HelloWorld or MyAddin.Connect.HelloWorld or
HelloWorld()
and tried defining the function static - all with no success.
So how can I trap my CommandBarButton click event in Visio add-in?
Please help
Thanks
Amitai