Quoted:
Quoted: I'm not a C# programmer, but +=?
|
Yeah, that seems odd to append a value to / from what seems to be an event handler.
Sure it's not just "="?
|
Ok, I just gave it another shot and it didnt work. The original code in the MS article looks like this:
private void CreateButton() {
try {
CommandBars cmdBars = (CommandBars)vsoApplication.CommandBars;
CommandBar cmdBar = null;
try {
cmdBar = cmdBars.Add(
"UserDiagram", MsoBarPosition.msoBarTop,
Missing.Value, true);
// Transform the next three lines of code to a single line of code.
CommandBarButton button = (CommandBarButton)cmdBar.Controls.Add(
MsoControlType.msoControlButton, Missing.Value, Missing.Value
Missing.Value, true);
button.Caption = "Create Users Diagram";
button.Style = MsoButtonStyle.msoButtonCaption;
// Transform the next three lines of code to a single line of code.
button.Click += new
_CommandBarButtonEvents_ClickEventHandler(button_Click);
cmdBar.Visible = true;
}
catch {
cmdBar = cmdBars["UserDiagram"];
}
}
catch(Exception ex) {
MessageBox.Show(
"Error while creating the toolbar:" + ex.ToString());
}
}
So, I put the parenthesis back around the button_Click and changed += to =, saved, and built and it failed with the following error:
C:\path\to\project\Connect.cs(103): The event 'Microsoft.Office.Core._CommandBarButtonEvents_Event.Click' can only appear on the left hand side of += or -=
So, when I make the code look like its supposed to right from the article it looks like this:
private void CreateButton()
{
try
{
CommandBars cmdBars = (CommandBars)vsoApplication.CommandBars;
CommandBar cmdBar = null;
try
{
cmdBar = cmdBars.Add(
"UserDiagram", MsoBarPosition.msoBarTop,
Missing.Value, true);
CommandBarButton button = (CommandBarButton)cmdBar.Controls.Add(MsoControlType.msoControlButton, Missing.Value, Missing.Value, Missing.Value, true);
button.Caption = "Create Users Diagram";
button.Style = MsoButtonStyle.msoButtonCaption;
button.Click += new_CommandBarButtonEvents_ClickEventHandler (button_Click);
cmdBar.Visible = true;
}
catch
{
cmdBar = cmdBars["UserDiagram"];
}
}
catch(Exception ex)
{
MessageBox.Show(
"Error while creating the toolbar:" + ex.ToString());
}
}
private void button_Click(CommandBarButton Ctrl, ref bool CancelDefault)
{
using(ConnectionDialog dialog = new ConnectionDialog())
{
if (dialog.ShowDialog() == DialogResult.OK)
{
DiagramGenerator dg = new DiagramGenerator(vsoApplication);
dg.CreateDiagram(dialog.DepartmentName, dialog.Users);
}
}
}
But, I get the following error:
C:\path\to\project\Connect.cs(103): Method 'VisioUserDiagrams.Connect.button_Click(Microsoft.Office.Core.CommandBarButton, ref bool)' referenced without parentheses
That caused me to take the parentheses out which then led me to the error that I stated in the initial post.