|
This sample demonstrates how to create a cancelable print progress window using a custom Print button. Caution: Clicking "Print" will send 200 pages to your printer. For your convenience, the code from this sample is below. Note: You must have build 1253 or later in order to run the attached sample. 'Code for frmMain Option Explicit Dim rpt As rptLarge Private Sub arv_ToolbarClick(ByVal Tool As DDActiveReportsViewer2Ctl.IDDTool) If Tool.Caption = "&Print..." Then frmProgress.AutoRedraw = True frmProgress.Show DoEvents rpt.Printer.DisplayProgressDialog = False frmProgress.lblStatus = "Printing..." frmProgress.ProgressBar1.Max = rpt.Pages.Count frmProgress.lblTotalPages = rpt.Pages.Count ' Use the True argument to display the printer dialog menu rpt.PrintReport False If frmProgress.bCancelled Then frmProgress.lblStatus = "Cancelled" frmProgress.bCancelled = False Else frmProgress.lblStatus = "Completed" frmProgress.btnCancel.Enabled = False End If 'Uncomment the following line of code if you would like the progress window to automatically ' close itself upon completion. 'frmProgress.Hide End If End Sub Private Sub Form_Load() 'Override the viewer's Print button Dim cnt As Integer For cnt = 0 To arv.Toolbar.Tools.Count - 1 If "&Print..." = arv.Toolbar.Tools(cnt).Caption Then arv.Toolbar.Tools(cnt).ID = 9999 arv.Toolbar.Tools(cnt).Enabled = True End If Next cnt Set rpt = New rptLarge rpt.Run Me.arv.ReportSource = rpt End Sub Private Sub Form_Unload(Cancel As Integer) 'Since a class-level report object was created, it needs to be properly destroyed If Not rpt = Nothing Then rpt.Pages.RemoveAll rpt = Nothing End If End Sub 'Class for rptLarge Private Sub ActiveReport_PrintProgress(ByVal pageNumber As Long) frmProgress.lblCurrentPage.Caption = pageNumber frmProgress.ProgressBar1.Value = frmProgress.ProgressBar1.Value + 1 If frmProgress.bCancelled Then Me.Cancel Me.Printer.AbortJob End If DoEvents End Sub 'Code for frmProgress Option Explicit Public bCancelled As Boolean Private Sub btnCancel_Click() bCancelled = True End Sub
Applies To: ActiveReports 2.0
|