方法: Windows フォームの印刷ジョブを完了する
多くの場合、印刷を行うことができるワード プロセッサやその他のアプリケーションには、印刷ジョブが完了したことをユーザーに示すオプションが用意されています。 Windows フォームでは、PrintDocument コンポーネントの EndPrint イベントを処理することでこの機能を提供できます。
次の手順では、PrintDocument コンポーネントを含む Windows ベースのアプリケーションを作成しておく必要があります。これは、Windows ベースのアプリケーションで印刷を有効にするための標準的な方法です。 PrintDocument コンポーネントを使用した Windows フォームでの印刷の詳細については、「方法: 標準の Windows フォーム印刷ジョブを作成する」を参照してください。
印刷ジョブを完了するには
PrintDocument コンポーネントの DocumentName プロパティを設定します。
PrintDocument1.DocumentName = "MyTextFile"
printDocument1.DocumentName = "MyTextFile";
printDocument1->DocumentName = "MyTextFile";
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(System::Object ^ sender, System::Drawing::Printing::PrintEventArgs ^ e) { MessageBox::Show(String::Concat(printDocument1->DocumentName, " has finished printing.")); }
(Visual C# および Visual C++) フォームのコンストラクターに次のコードを配置して、イベント ハンドラーを登録します。
this.printDocument1.EndPrint += new System.Drawing.Printing.PrintEventHandler (this.printDocument1_EndPrint);
this->printDocument1->EndPrint += gcnew System::Drawing::Printing::PrintEventHandler (this, &Form1::printDocument1_EndPrint);
関連項目
GitHub で Microsoft と共同作業する
このコンテンツのソースは GitHub にあります。そこで、issue や pull request を作成および確認することもできます。 詳細については、共同作成者ガイドを参照してください。
.NET Desktop feedback