Document.BeforeClose 事件

刚好在文档关闭之前发生。

命名空间:  Microsoft.Office.Tools.Word
程序集:  Microsoft.Office.Tools.Word(在 Microsoft.Office.Tools.Word.dll 中)

语法

声明
Event BeforeClose As CancelEventHandler
event CancelEventHandler BeforeClose

备注

该事件发生在文档关闭之前。 若要防止文档关闭,请将所提供的 CancelEventArgs 对象的 Cancel 参数设置为 true。

示例

下面的代码示例在文档关闭之前显示一个消息框。 此示例针对的是应用程序级外接程序。

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
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.");
}

.NET Framework 安全性

请参见

参考

Document 接口

Microsoft.Office.Tools.Word 命名空间