I need to create my own toolbar with set of buttons in the Visio window. The next code generates toolbar (it works), create buttons (it works), and assign Click events handlers for them.
vsoCommandBar = vsoCommandBars.Add("MyCommandBat", Office.MsoBarPosition.msoBarTop, false, true);
var vsoButtonX1 = (Office.CommandBarButton)vsoCommandBar.Controls.Add(
Office.MsoControlType.msoControlButton, 1, 2, 1, false);
vsoButtonX1.Caption = "Test1";
vsoButtonX1.Tag = "";
vsoButtonX1.Click += GlobalEvents.btnTestClick;
var vsoButtonX2 = (Office.CommandBarButton)vsoCommandBar.Controls.Add(
Office.MsoControlType.msoControlButton, 1, 2, 2, false);
vsoButtonX2.Caption = "Test2";
vsoButtonX2.Tag = "";
vsoButtonX2.Click += GlobalEvents.btnTest2Click;
Handlers are simple, but different (of course).
public void btnTestClick(Office.CommandBarButton vsoButton, ref bool cancelDefault)
{
MessageBox.Show("btnTestClick!");
}
public void btnTest2Click(Office.CommandBarButton vsoButton, ref bool cancelDefault)
{
MessageBox.Show("btnTest2Click!");
}
When I click on any button I see dialog with "btnTestClick!" and after pressing "OK" dialog with "btnTest2Click!". On any of two buttons.
Moreover, if I skip this line:
vsoButtonX2.Click += GlobalEvents.btnTest2Click;
I'll see single dialog "btnTestClick!" on any button.
It seems that it has only one click processor at least for a command bar. Is it true?!
PS: Of course, I can use "vsoButton" parameter and tags to detect wht button is pressed, but it seems more convinient to use different event handlers... It's possible?