Document.BeforePrint 事件
在列印文件之前發生。
命名空間: Microsoft.Office.Tools.Word
組件: Microsoft.Office.Tools.Word (在 Microsoft.Office.Tools.Word.dll 中)
語法
'宣告
Event BeforePrint As CancelEventHandler
event CancelEventHandler BeforePrint
備註
若要防止列印文件,請將提供的 CancelEventArgs 物件的 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
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;
}
}
.NET Framework 安全性
- 完全信任立即呼叫者。這個成員無法供部分信任的程式碼使用。如需詳細資訊,請參閱從部分受信任程式碼使用程式庫。