Document.BeforePrint Ereignis

Definition

Wird ausgelöst, bevor das Dokument gedruckt wird.

event System.ComponentModel.CancelEventHandler BeforePrint;

Ereignistyp

CancelEventHandler

Beispiele

Im folgenden Codebeispiel wird eine Meldung angezeigt, bevor das Dokument gedruckt wird, in dem Sie gefragt werden, ob das Dokument gedruckt werden soll. Dieses Beispiel gilt für ein Add-in auf Anwendungsebene.

private void DocumentBeforePrint()
{
    Document vstoDoc = Globals.Factory.GetVstoObject(this.Application.ActiveDocument);
    vstoDoc.BeforePrint += new System.ComponentModel.CancelEventHandler(ThisDocument_BeforePrint);
}

void ThisDocument_BeforePrint(object sender, System.ComponentModel.CancelEventArgs e)
{
    if (System.Windows.Forms.MessageBox.Show("Do you want to print the document?", "BeforePrint",
        System.Windows.Forms.MessageBoxButtons.YesNo) == System.Windows.Forms.DialogResult.No)
    {
        e.Cancel = true;
    }
}
Private Sub DocumentBeforePrint()
    Dim vstoDoc As Document = Globals.Factory.GetVstoObject(Me.Application.ActiveDocument)
    AddHandler vstoDoc.BeforePrint, AddressOf ThisDocument_BeforePrint
End Sub

Private Sub ThisDocument_BeforePrint(ByVal sender As Object, ByVal e As System. _
    ComponentModel.CancelEventArgs)
    Dim vstoDoc As Document = Globals.Factory.GetVstoObject(Me.Application.ActiveDocument)
    If System.Windows.Forms.MessageBox.Show("Do you want to print the document?", "BeforePrint", _
        System.Windows.Forms.MessageBoxButtons.YesNo) = System.Windows.Forms.DialogResult.No Then
        e.Cancel = True
    End If
End Sub

Hinweise

Um zu verhindern, dass das Dokument gedruckt wird, legen Sie das- Cancel Argument des bereitgestellten- CancelEventArgs Objekts auf fest true .

Gilt für