Document.BeforePrint 事件
定义
重要
一些信息与预发行产品相关,相应产品在发行之前可能会进行重大修改。 对于此处提供的信息,Microsoft 不作任何明示或暗示的担保。
在打印文档之前发生。
event System.ComponentModel.CancelEventHandler BeforePrint;
事件类型
示例
下面的代码示例在打印文档之前显示一条消息,询问您是否要打印文档。 此示例适用于应用程序级外接程序。
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
注解
若要防止打印文档,请将 Cancel 提供的对象的参数设置 CancelEventArgs 为 true 。