Document.BeforePrint (Evento)
Se produce antes de que se imprima el documento.
Espacio de nombres: Microsoft.Office.Tools.Word
Ensamblado: Microsoft.Office.Tools.Word (en Microsoft.Office.Tools.Word.dll)
Sintaxis
'Declaración
Event BeforePrint As CancelEventHandler
event CancelEventHandler BeforePrint
Comentarios
Para impedir que el documento se imprima, establezca el argumento Cancel del objeto CancelEventArgs proporcionado como true.
Ejemplos
En el ejemplo de código siguiente se muestra un mensaje antes de que el documento se imprima que pregunta si desea imprimir el documento. Se trata de un ejemplo para un complemento en el nivel de la aplicación.
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;
}
}
Seguridad de .NET Framework
- Plena confianza para el llamador inmediato. Un código de confianza parcial no puede utilizar este miembro. Para obtener más información, vea Utilizar bibliotecas de código que no es de plena confianza.