Udostępnij za pośrednictwem


DocumentBase.BeforeClose Event

Occurs immediately before the document closes.

Namespace:  Microsoft.Office.Tools.Word
Assembly:  Microsoft.Office.Tools.Word.v4.0.Utilities (in Microsoft.Office.Tools.Word.v4.0.Utilities.dll)

Syntax

'Declaration
Public Event BeforeClose As CancelEventHandler
public event CancelEventHandler BeforeClose

Remarks

The event occurs before the document closes. To keep the document from closing, set the Cancel argument of the provided CancelEventArgs object to true.

Examples

The following code example displays a message box before the document closes. To use this example, run it from the ThisDocument class in a document-level project.

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

.NET Framework Security

See Also

Reference

DocumentBase Class

Microsoft.Office.Tools.Word Namespace