DocumentBase.BeforeSave 事件

定义

在保存文档之前发生。

public event Microsoft.Office.Tools.Word.SaveEventHandler BeforeSave;

事件类型

SaveEventHandler

示例

下面的代码示例在保存文档之前显示一条消息,询问您是否要保存该文档。 若要使用此示例,请在 ThisDocument 文档级项目的类中运行它。

private void DocumentBeforeSave()
{
    this.BeforeSave += new Microsoft.Office.Tools.Word.SaveEventHandler(ThisDocument_BeforeSave);
}

void ThisDocument_BeforeSave(object sender, Microsoft.Office.Tools.Word.SaveEventArgs e)
{
    if (MessageBox.Show("Do you want to save the document?", "BeforeSave",
        MessageBoxButtons.YesNo) == DialogResult.No)
    {
        e.Cancel = true;
    }
}
Private Sub DocumentBeforeSave()
    AddHandler Me.BeforeSave, AddressOf ThisDocument_BeforeSave
End Sub

Private Sub ThisDocument_BeforeSave(ByVal sender As Object, ByVal e As Microsoft.Office.Tools.Word.SaveEventArgs)
    If MessageBox.Show("Do you want to save the document?", "BeforeSave", _
        MessageBoxButtons.YesNo) = DialogResult.No Then
        e.Cancel = True
    End If
End Sub

注解

若要阻止保存文档,请将 Cancel 提供的对象的参数设置 CancelEventArgstrue

适用于