InfoPath - On Load Event - Hide all Menus
- How can i hide all menu's for infopath using the OnLoad Event?
Answers
Hello Martin,
In my said, I have made test. When I open a .xsn file by File->Open, it will trigger the NewXDocument and OnLoad event. I add code to OnLoad event handler, and finally the menus are invisible. Here is the code,
private InfoPath._Application3 InfoPathApplication = null;
private InfoPath.ApplicationEvents InfoPahtApplicationEvents = null;
InfoPath.XDocument xdocument;
Office.CommandBar commandbar;
private void ThisAddIn_Startup(object sender, System.EventArgs e)
{
InfoPathApplication = this.Application as InfoPath._Application3;
InfoPahtApplicationEvents = InfoPathApplication.Events as InfoPath.ApplicationEvents;
InfoPahtApplicationEvents.NewXDocument += new InfoPath._ApplicationEvents_NewXDocumentEventHandler(InfoPahtApplicationEvents_NewXDocument);
}void InfoPahtApplicationEvents_NewXDocument(Microsoft.Office.Interop.InfoPath._XDocument pDocument)
{
MessageBox.Show("Hello");
commandbar = (this.Application.ActiveWindow.CommandBars as Office.CommandBars).ActiveMenuBar; xdocument = pDocument as InfoPath.XDocument;
xdocument.OnLoad += new Microsoft.Office.Interop.InfoPath._XDocumentEventSink2_OnLoadEventHandler(xdocument_OnLoad);
}void xdocument_OnLoad(Microsoft.Office.Interop.InfoPath.DocReturnEvent pEvent)
{
MessageBox.Show("OnLoad");
int count = commandbar.Controls.Count;
for (int i = 1; i <= count; i++)
{
commandbar.Controls[i].Visible = false;
}
}
Here are some resources which may interest you.
Creating InfoPath 2007 Add-Ins by Using Visual Studio 2005 Tools for the Office System SE.
XDocument.OnLoad Event.
Best regards,
Bessie
Please remember to mark the replies as answers if they help and unmark them if they provide no help.
Welcome to the All-In-One Code Framework! If you have any feedback, please tell us.- Marked As Answer byBessie ZhaoMSFT, ModeratorFriday, November 13, 2009 6:08 AM
All Replies
Hello Martin,
In my said, I have made test. When I open a .xsn file by File->Open, it will trigger the NewXDocument and OnLoad event. I add code to OnLoad event handler, and finally the menus are invisible. Here is the code,
private InfoPath._Application3 InfoPathApplication = null;
private InfoPath.ApplicationEvents InfoPahtApplicationEvents = null;
InfoPath.XDocument xdocument;
Office.CommandBar commandbar;
private void ThisAddIn_Startup(object sender, System.EventArgs e)
{
InfoPathApplication = this.Application as InfoPath._Application3;
InfoPahtApplicationEvents = InfoPathApplication.Events as InfoPath.ApplicationEvents;
InfoPahtApplicationEvents.NewXDocument += new InfoPath._ApplicationEvents_NewXDocumentEventHandler(InfoPahtApplicationEvents_NewXDocument);
}void InfoPahtApplicationEvents_NewXDocument(Microsoft.Office.Interop.InfoPath._XDocument pDocument)
{
MessageBox.Show("Hello");
commandbar = (this.Application.ActiveWindow.CommandBars as Office.CommandBars).ActiveMenuBar; xdocument = pDocument as InfoPath.XDocument;
xdocument.OnLoad += new Microsoft.Office.Interop.InfoPath._XDocumentEventSink2_OnLoadEventHandler(xdocument_OnLoad);
}void xdocument_OnLoad(Microsoft.Office.Interop.InfoPath.DocReturnEvent pEvent)
{
MessageBox.Show("OnLoad");
int count = commandbar.Controls.Count;
for (int i = 1; i <= count; i++)
{
commandbar.Controls[i].Visible = false;
}
}
Here are some resources which may interest you.
Creating InfoPath 2007 Add-Ins by Using Visual Studio 2005 Tools for the Office System SE.
XDocument.OnLoad Event.
Best regards,
Bessie
Please remember to mark the replies as answers if they help and unmark them if they provide no help.
Welcome to the All-In-One Code Framework! If you have any feedback, please tell us.- Marked As Answer byBessie ZhaoMSFT, ModeratorFriday, November 13, 2009 6:08 AM


