Document.BeforeClose 事件
定义
重要
一些信息与预发行产品相关,相应产品在发行之前可能会进行重大修改。 对于此处提供的信息,Microsoft 不作任何明示或暗示的担保。
刚好在文档关闭之前发生。
event System.ComponentModel.CancelEventHandler BeforeClose;
事件类型
示例
下面的代码示例在文档关闭之前显示一个消息框。 此示例适用于应用程序级外接程序。
private void DocumentBeforeClose()
{
Document vstoDoc = Globals.Factory.GetVstoObject(this.Application.ActiveDocument);
vstoDoc.BeforeClose += new System.ComponentModel.CancelEventHandler(ThisDocument_BeforeClose);
}
void ThisDocument_BeforeClose(object sender, System.ComponentModel.CancelEventArgs e)
{
System.Windows.Forms.MessageBox.Show("The document is closing.");
}
Private Sub DocumentBeforeClose()
Dim vstoDoc As Document = Globals.Factory.GetVstoObject(Me.Application.ActiveDocument)
AddHandler vstoDoc.BeforeClose, AddressOf ThisDocument_BeforeClose
End Sub
Private Sub ThisDocument_BeforeClose(ByVal sender As Object, _
ByVal e As System.ComponentModel.CancelEventArgs)
System.Windows.Forms.MessageBox.Show("The document is closing.")
End Sub
注解
该事件在文档关闭之前发生。 若要保持文档关闭,请将 Cancel 提供的对象的参数设置 CancelEventArgs 为 true 。