Document.BeforeClose 事件 (2007 system)

更新: 2008 年 7 月

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

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

语法

声明
Public Event BeforeClose As CancelEventHandler
用法
Dim instance As Document
Dim handler As CancelEventHandler

AddHandler instance.BeforeClose, handler
public event CancelEventHandler BeforeClose

备注

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

示例

下面的代码示例在文档关闭之前显示一个消息框。

Private Sub DocumentBeforeClose()
    AddHandler Me.BeforeClose, AddressOf ThisDocument_BeforeClose
End Sub

Private Sub ThisDocument_BeforeClose(ByVal sender As Object, ByVal e As System.ComponentModel.CancelEventArgs)
    MessageBox.Show("The document is closing.")
End Sub
private void DocumentBeforeClose()
{
    this.BeforeClose += new System.ComponentModel.CancelEventHandler(ThisDocument_BeforeClose);
}

void ThisDocument_BeforeClose(object sender, System.ComponentModel.CancelEventArgs e)
{
    MessageBox.Show("The document is closing.");
}

此版本针对的是应用程序级外接程序。

Private Sub DocumentBeforeClose()
    Dim vstoDoc As Document = Me.Application.ActiveDocument.GetVstoObject()
    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 = this.Application.ActiveDocument.GetVstoObject();
    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.");
}

权限

另请参见

参考

Document 类

Document 成员

Microsoft.Office.Tools.Word 命名空间

修订记录

日期

修订记录

原因

2008 年 7 月

添加了一个针对应用程序级外接程序的代码示例版本。

SP1 功能更改。