Evento Document.BeforePrint

Viene generato prima della stampa del documento.

Spazio dei nomi:  Microsoft.Office.Tools.Word
Assembly:  Microsoft.Office.Tools.Word (in Microsoft.Office.Tools.Word.dll)

Sintassi

'Dichiarazione
Event BeforePrint As CancelEventHandler
event CancelEventHandler BeforePrint

Note

Per evitare la stampa del documento, impostare l'argomento Cancel dell'oggetto CancelEventArgs fornito su true.

Esempi

Nell'esempio di codice riportato di seguito viene illustrato come visualizzare un messaggio prima della stampa del documento per chiedere conferma dell'operazione. Questo esempio è valido per un componente aggiuntivo a livello di applicazione.

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

Sicurezza di .NET Framework

Vedere anche

Riferimenti

Document Interfaccia

Spazio dei nomi Microsoft.Office.Tools.Word