作成日: 2022/04/20 最終更新日: 2022/07/19
文書種別
使用方法
詳細
印刷処理の完了を判断する方法としては、.NET FrameworkのSystem.Drawing.Printing.PrintDocumentクラスから継承される、SectionDocumentまたはPageDocumentクラスのPrinterプロパティのEndPrintイベントを利用する方法が考えられます。
具体的な実装方法は、レポート形式によって異なります。
セクションレポートの場合
◆サンプルコード (C#)
private void Form1_Load(object sender, EventArgs e)
{
// セクションレポートをViewerに表示します。
var sectionReport = new SectionReport1();
sectionReport.Run();
this.viewer1.Document = sectionReport.Document;
// EndPrintイベントをイベントハンドラに関連付けます。
sectionReport.Document.Printer.EndPrint += new System.Drawing.Printing.PrintEventHandler(onEndPrint);
}
// 印刷処理の終了時に発生するイベント
private void onEndPrint(object sender, System.Drawing.Printing.PrintEventArgs e)
{
Console.WriteLine("印刷完了");
}
◆サンプルコード (VB.NET)
Private Sub Form1_Load(...) Handles MyBase.Load
' セクションレポートをViewerに表示します。
Dim sectionReport As New SectionReport1
sectionReport.Run()
Me.Viewer1.Document = sectionReport.Document
' EndPrintイベントをイベントハンドラに関連付けます。
AddHandler sectionReport.Document.Printer.EndPrint, AddressOf Me.onEndPrint
End Sub
' 印刷処理の終了時に発生するイベント
Private Sub onEndPrint(ByVal sender As Object, ByVal e As System.Drawing.Printing.PrintEventArgs)
Console.WriteLine("印刷完了")
End Sub
ページレポート/RDLレポートの場合
◆サンプルコード (C#)
private void Form1_Load(object sender, EventArgs e)
{
// レポートをViewerに表示します。
string file_name = @"..¥..¥PageReport1.rdlx";
var pageReport = new GrapeCity.ActiveReports.PageReport(new System.IO.FileInfo(file_name));
var pageDocument = new GrapeCity.ActiveReports.Document.PageDocument(pageReport);
this.viewer1.LoadDocument(pageDocument);
// EndPrintイベントをイベントハンドラに関連付けます。
pageDocument.Printer.EndPrint += new System.Drawing.Printing.PrintEventHandler(onEndPrint);
}
// 印刷処理の終了時に発生するイベント
private void onEndPrint(object sender, System.Drawing.Printing.PrintEventArgs e)
{
Console.WriteLine("印刷完了");
}
◆サンプルコード (VB.NET)
Private Sub Form1_Load(...) Handles MyBase.Load
' レポートをViewerに表示します。
Dim file_name As String = "..¥..¥PageReport1.rdlx"
Dim pageReport As New GrapeCity.ActiveReports.PageReport(New System.IO.FileInfo(file_name))
Dim pageDocument As New GrapeCity.ActiveReports.Document.PageDocument(pageReport)
Me.Viewer1.LoadDocument(pageDocument)
' EndPrintイベントをイベントハンドラに関連付けます。
AddHandler pageDocument.Printer.EndPrint, AddressOf Me.onEndPrint
End Sub
' 印刷処理の終了時に発生するイベント
Private Sub onEndPrint(ByVal sender As Object, ByVal e As System.Drawing.Printing.PrintEventArgs)
Console.WriteLine("印刷完了")
End Sub
※注意事項
バージョン16.0JでPageDocument.PrinterプロパティはObsolete(廃止予定)になりました。
そのため、上記のコードは警告が表示されますが、代替となる方法は用意されておりません。
バージョン16.0Jでは利用可能ですので、警告は無視してください。