Udostępnij za pośrednictwem


DocumentBase.BeforePrint Event

Occurs before the document is printed.

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 BeforePrint As CancelEventHandler
public event CancelEventHandler BeforePrint

Remarks

To prevent the document from printing, set the Cancel argument of the provided CancelEventArgs object to true.

Examples

The following code example displays a message before the document is printed that asks whether you want to print the document. To use this example, run it from the ThisDocument class in a document-level project.

Private Sub DocumentBeforePrint()
    AddHandler Me.BeforePrint, AddressOf ThisDocument_BeforePrint
End Sub

Private Sub ThisDocument_BeforePrint(ByVal sender As Object, ByVal e As System. _
    ComponentModel.CancelEventArgs)
    If MessageBox.Show("Do you want to print the document?", "BeforePrint", _
        MessageBoxButtons.YesNo) = DialogResult.No Then
        e.Cancel = True
    End If
End Sub
private void DocumentBeforePrint()
{
    this.BeforePrint += new System.ComponentModel.CancelEventHandler(ThisDocument_BeforePrint);
}

void ThisDocument_BeforePrint(object sender, System.ComponentModel.CancelEventArgs e)
{
    if (MessageBox.Show("Do you want to print the document?", "BeforePrint",
        MessageBoxButtons.YesNo) == DialogResult.No)
    {
        e.Cancel = true;
    }
}

.NET Framework Security

See Also

Reference

DocumentBase Class

Microsoft.Office.Tools.Word Namespace