我是ActiveReport的新手。
我有一个使用ActiveReport 2.0的遗留VB6代码。打印流程如下(代码为VB,ar的初始化未显示)
Dim ar as DDActiveReports2.ActiveReport
Dim aborted As Boolean
aborted = False
ar.Printer.StartJob("some job")
For i = 0 To ar.Pages.Count - 1
ar.Printer.StartPage()
If ar.Printer.Status = DDActiveReports2.JobStatus.ddJSAborted Then
ar.Printer.AbortJob()
aborted = True
Exit For
End If
ar.Printer.PrintPage(ar.Pages(i), left, top, width, height)
ar.Printer.EndPage()
Next
If Not Aborted Then
ar.Printer.EndJob()
End If
我正在尝试将其迁移到ActiveReport for .NET。经过一些研究,我发现这里最好的替代品是ActiveReports.SystemPrinter。迁移的代码可能如下所示(未显示ar的初始化),
Dim ar As ActiveReports.Document.SectionDocument
Dim aborted As Boolean = False
Dim printer As New ActiveReports.SystemPrinter
printer.StartJob("some job")
For i = 0 To ar.Pages.Count - 1
printer.StartPage()
If ??? Then
printer.AbortJob()
aborted = True
Exit For
End If
ar.Pages(i).Draw(printer.Graphics, New RectangleF(left, top, width, height))
printer.EndPage()
Next
If Not Aborted Then
printer.EndJob()
End If
但是,我在ActiveReport2中找不到printer.Status,并且无法知道打印中止状态DDActiveReports2.JobStatus.ddJSAborted。
我真的不太确定DDActiveReports2.JobStatus.ddJSAborted是什么,我的猜测是用户可以在Windows Printing Tasks窗口中取消打印。取消后,程序将取消所有剩余页面。
但是,这似乎无法在.NET中完成?我错过了什么吗?
请帮忙。
谢谢。
.NET版本中的SectionDocument类具有PrintAborted事件处理程序。这是一个代码示例:
导入GrapeCity.ActiveReports
导入GrapeCity.ActiveReports.Document
Dim WithEvents my_document As SectionDocument
Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
my_document = New SectionDocument()
my_document.Load(ms)
my_document.Print(False)
End Sub
Private Sub PrintAborted(sender As Object, e As EventArgs) Handles my_document.PrintAborted
MsgBox("PrintAborted")
End Sub
请不要忘记将项目中的引用添加到GrapeCity.ActiveReports.Extensibility.dll和GrapeCity.ActiveReports.Viewer.Win.dll
谢谢,