I am trying to write an application-level add-in for Word 2003. The plugin adds a button to the new control panel - clicking the button saves the active document and then performs some additional actions. When I start Word 2003, and then press the button on my command bar, everything works fine. However, if I started Word 2003, open a new Word window by clicking the button on the "New Document" toolbar in the "Standard" toolbar, and then click the "My Panel" button and you will see that no actions are performed. It seems that my toolbar button in the new window that opens does not have an onclick event handler assigned. Do you have any idea how to solve the problem?
My add-in code is based on the following code:
private Office.CommandBar commandBar;
private Office.CommandBarButton docSaveButton;
private void ThisAddIn_Startup(object sender, System.EventArgs e)
{
try
{
commandBar = Application.CommandBars["MY_TOOLBAR"];
}
catch (ArgumentException)
{
}
if (commandBar == null)
{
commandBar = Application.CommandBars.Add("MY_TOOLBAR", 1, missing, true);
}
commandBar.Visible = true;
docSaveButton = (Office.CommandBarButton)commandBar.Controls.Add(1, missing, missing, missing, missing);
docSaveButton.Style = Microsoft.Office.Core.MsoButtonStyle.msoButtonIcon;
docSaveButton.Caption = "My save";
docSaveButton.Click += new Office._CommandBarButtonEvents_ClickEventHandler(docSaveButtonClick);
}
private void docSaveButtonClick(Office.CommandBarButton ctrl, ref bool cancel)
{
MessageBox.Show("Hello !", "Hello !", MessageBoxButtons.OK, MessageBoxIcon.Information);
}
Relationship jank
user255659