Share via


方法 : Windows フォームの印刷ジョブを完了する

更新 : 2007 年 11 月

印刷ジョブを伴うワード プロセッサやその他のアプリケーションでは、多くの場合、印刷ジョブが完了したというメッセージをユーザーに表示するオプションが用意されています。PrintDocument コンポーネントの EndPrint イベントを処理することによって、Windows フォームにこの機能を用意できます。

次の手順では、PrintDocument コンポーネントのある Windows ベースのアプリケーションを作成している必要があります。これは Windows ベースのアプリケーションからの印刷を有効にする標準的な方法です。PrintDocument コンポーネントを使用した Windows フォームからの印刷の詳細については、「方法 : 標準の Windows フォーム印刷ジョブを作成する」を参照してください。

印刷ジョブを完了するには

  1. PrintDocument コンポーネントの DocumentName プロパティを設定します。

    PrintDocument1.DocumentName = "MyTextFile"
    
    printDocument1.DocumentName = "MyTextFile";
    
    printDocument1.set_DocumentName("MyTextFile");
    
    printDocument1->DocumentName = "MyTextFile";
    
  2. EndPrint イベントを処理するコードを記述します。

    次のコード例では、ドキュメントの印刷が完了したことを示すメッセージ ボックスが表示されます。

    Private Sub PrintDocument1_EndPrint(ByVal sender As Object, ByVal e As System.Drawing.Printing.PrintEventArgs) Handles PrintDocument1.EndPrint
       MessageBox.Show(PrintDocument1.DocumentName + " has finished printing.")
    End Sub
    
    private void printDocument1_EndPrint(object sender, 
    System.Drawing.Printing.PrintEventArgs e)
    {
       MessageBox.Show(printDocument1.DocumentName + 
          " has finished printing.");
    }
    
    private void printDocument1_EndPrint(Object sender,
    System.Drawing.Printing.PrintEventArgs e)
    {
       MessageBox.Show(printDocument1.get_DocumentName() +
          " has finished printing.");
    }
    
    private:
       void printDocument1_EndPrint(System::Object ^ sender,
          System::Drawing::Printing::PrintEventArgs ^ e)
       {
          MessageBox::Show(String::Concat(printDocument1->DocumentName,
             " has finished printing."));
       }
    

    (Visual C#、Visual J#、および Visual C++) フォームのコンストラクタに次のコードを挿入してイベント ハンドラを登録します。

    this.printDocument1.EndPrint += new
       System.Drawing.Printing.PrintEventHandler
       (this.printDocument1_EndPrint);
    
    this.printDocument1.add_EndPrint(new System.Drawing.Printing.PrintEventHandler(
    this.printDocument1_EndPrint));
    
    this->printDocument1->EndPrint += gcnew
       System::Drawing::Printing::PrintEventHandler
       (this, &Form1::printDocument1_EndPrint);
    

参照

参照

PrintDocument

その他の技術情報

Windows フォームにおける印刷のサポート