M
Mike
Menu creation architectural question [VSTO, C#]:
Hi! I am creating MS Word 2003 template with custom built menus and getting
confused on how it works. What I do not understand is at what point the code
will build the menu? I mean should I run this code every time the template
launches? Should I check if the menu is built already? I get prompts to save
the template but have no clue what causes the prompt? Is this the best
solution/architecture? All I want is to build a template which will be
programmatically attached to a Word 2003 document that’s going to be launched
from a C# executable. What makes it even more interesting is that I see the
menu when I launch (F5) in VS IDE for a second and then it disappears. What
am I doing wrong. Please help.
Any ideas/suggestions are greatly appreciated.
Here’s how I create a menu item:
protected void ThisDocument_New()
{
try
{
this.MainMenuBar = ThisApplication.CommandBars["Menu Bar"];
InitMenuBarItems("&Travel Tools");
this.MenuItem = this.CreateButton((Office.CommandBarPopup)this.MenuBarItem,
"& Expense Report");
this.MenuItem.Click += new
Office._CommandBarButtonEvents_ClickEventHandler(MenuItem_Click);
}
catch(Exception ex)
{
MessageBox.Show(ex.Message, ex.Source, MessageBoxButtons.OK,
MessageBoxIcon.Error);
}
}
private Office.CommandBarButton CreateButton(Office.CommandBarPopup Parent,
string Caption)
{
Office.CommandBarControl cbc = null;
try
{
cbc = Parent.Controls.
Add(Office.MsoControlType.msoControlButton,
Type.Missing, Type.Missing, Type.Missing, true);
cbc.Caption = Caption;
cbc.Visible = true;
}
catch (Exception ex)
{
MessageBox.Show(ex.Message, ex.Source, MessageBoxButtons.OK,
MessageBoxIcon.Error);
}
return (Office.CommandBarButton)cbc;
}
Thank you in advance,
Hi! I am creating MS Word 2003 template with custom built menus and getting
confused on how it works. What I do not understand is at what point the code
will build the menu? I mean should I run this code every time the template
launches? Should I check if the menu is built already? I get prompts to save
the template but have no clue what causes the prompt? Is this the best
solution/architecture? All I want is to build a template which will be
programmatically attached to a Word 2003 document that’s going to be launched
from a C# executable. What makes it even more interesting is that I see the
menu when I launch (F5) in VS IDE for a second and then it disappears. What
am I doing wrong. Please help.
Any ideas/suggestions are greatly appreciated.
Here’s how I create a menu item:
protected void ThisDocument_New()
{
try
{
this.MainMenuBar = ThisApplication.CommandBars["Menu Bar"];
InitMenuBarItems("&Travel Tools");
this.MenuItem = this.CreateButton((Office.CommandBarPopup)this.MenuBarItem,
"& Expense Report");
this.MenuItem.Click += new
Office._CommandBarButtonEvents_ClickEventHandler(MenuItem_Click);
}
catch(Exception ex)
{
MessageBox.Show(ex.Message, ex.Source, MessageBoxButtons.OK,
MessageBoxIcon.Error);
}
}
private Office.CommandBarButton CreateButton(Office.CommandBarPopup Parent,
string Caption)
{
Office.CommandBarControl cbc = null;
try
{
cbc = Parent.Controls.
Add(Office.MsoControlType.msoControlButton,
Type.Missing, Type.Missing, Type.Missing, true);
cbc.Caption = Caption;
cbc.Visible = true;
}
catch (Exception ex)
{
MessageBox.Show(ex.Message, ex.Source, MessageBoxButtons.OK,
MessageBoxIcon.Error);
}
return (Office.CommandBarButton)cbc;
}
Thank you in advance,