Partager via


DocumentBase.BeforeClose Event

Definition

Occurs immediately before the document closes.

public:
 event System::ComponentModel::CancelEventHandler ^ BeforeClose;
public event System.ComponentModel.CancelEventHandler BeforeClose;
member this.BeforeClose : System.ComponentModel.CancelEventHandler 
Public Custom Event BeforeClose As CancelEventHandler 

Event Type

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 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()
    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

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.

Applies to