次の方法で共有


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 セキュリティ

  • 直前の呼び出し元に対する完全な信頼。 このメンバーは、部分的に信頼されているコードから使用することはできません。 詳細については、「部分信頼コードからのライブラリの使用」を参照してください。

参照

参照

Document インターフェイス

Microsoft.Office.Tools.Word 名前空間