Udostępnij za pośrednictwem


SaveEventHandler Delegate (2007 System)

Represents the method that will handle the BeforeSave event of a Document.

This API is not CLS-compliant. 

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

Syntax

'Declaration
<CLSCompliantAttribute(False)> _
Public Delegate Sub SaveEventHandler ( _
    sender As Object, _
    e As SaveEventArgs _
)
'Usage
Dim instance As New SaveEventHandler(AddressOf HandlerMethod)
[CLSCompliantAttribute(false)]
public delegate void SaveEventHandler(
    Object sender,
    SaveEventArgs e
)
[CLSCompliantAttribute(false)]
public delegate void SaveEventHandler(
    Object^ sender, 
    SaveEventArgs^ e
)
JScript does not support delegates.

Parameters

Remarks

When you create a SaveEventHandler delegate, you identify the method that will handle the event. To associate the event with your event handler, add an instance of the delegate to the event. The event handler is called whenever the event occurs, until you remove the delegate. For more information about delegates, see Events and Delegates.

Examples

The following code example demonstrates an event handler for the BeforeSave event. When you save the document, the event handler prompts you to cancel or continue with the save operation.

This example is for a document-level customization.

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
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;
    }
}

See Also

Reference

Microsoft.Office.Tools.Word Namespace