Document.BeforeClose Событие

Определение

Событие происходит непосредственно перед закрытием документа.

event System.ComponentModel.CancelEventHandler BeforeClose;

Тип события

CancelEventHandler

Примеры

В следующем примере кода перед закрытием документа выводится окно сообщения. Этот пример предназначен для надстройки уровня приложения.

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 .

Применяется к