我正在使用C#开发Word应用程序加载项。
我正在尝试使用该DocumentBeforeClose
事件:
Microsoft.Office.Tools.Word.Document vstoDoc = Globals.Factory.GetVstoObject(this.Application.ActiveDocument);
vstoDoc.BeforeClose += new System.ComponentModel.CancelEventHandler(ThisDocument_BeforeClose);
我可以处理它,但是当我尝试关闭并打开文档(不是整个应用程序)时,我将无法再处理此事件。
编辑:
DocumentBeforeClose很不错。
但是我如何使用ref bool取消
我尝试:
void Application_DocumentBeforeClose(_Word.Document Doc, ref bool Cancel)
{
Cancel = true;
}
但是它不起作用:(
您注册的事件处理程序位于一个特定的文档中。如果关闭它,事件处理程序将不计入后续文档。
如果您不希望BeforeClose
某个特定文档触发该事件,而是想要打开的任何文档触发该事件,请使用该Application.DocumentBeforeClose
事件。
Globals.ThisAddIn.Application.DocumentBeforeClose += Application_DocumentBeforeClose;
void Application_DocumentBeforeClose(_Word.Document Doc, ref bool Cancel)
{
// Doc is the document getting closed
}
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句