如何在ReportViewer1.Print事件中取消打印?

时间:2016-07-05 14:56:45

标签: .net vb.net reporting-services rdlc reportviewer

我创建了ReportViewer1。它将显示预览,当用户单击工具栏上的“打印”按钮时,我需要取消打印到打印机。

喜欢这个

Private Sub ReportViewer1_Print(sender As Object, e As ReportPrintEventArgs) _
  Handles ReportViewer1.Print
    Me.ReportViewer1.CancelRendering(0)   ''/ <----Cancel Printing
    RaiseEvent Click_Print(False)
End Sub

但是CancelRendering无效,因为它显示了所选打印机的dialogSetting。

1 个答案:

答案 0 :(得分:1)

您可以使用以下代码停止打印事件:

Private Sub ReportViewer1_Print(sender As Object, e As Microsoft.Reporting.WinForms.ReportPrintEventArgs) Handles ReportViewer1.Print

    e.Cancel = True

    MsgBox("Print stopped!")

End Sub

如果您不想允许打印,可能最好将打印按钮设置ShowPrintButton属性隐藏到False