C#中如何不显示PrintDialog()直接打印rdlc报告?我有一个应用程序,我必须打印RDLC报告而不显示printDialog并使用应用程序中定义的默认指定打印机。下面是我的测试实现代码。Microsoft.Reporting.WinForms.ReportViewerreportViewerSales=newMicrosoft.Reporting.WinForms.ReportViewer();Microsoft.Reporting.WinForms.ReportDataSourcereportDataSourceSales=newMicrosoft.Reporting.WinForms.ReportDataSource();reportViewerSales.Reset();reportViewerSales.LocalReport.ReportPath=@"Sales.rdlc";reportDataSourceSales.Name="SalesTableDataSet";诠释我=1;foreach(ProductSalesList中的产品项目){dataset.CurrentSales.AddCurrentSalesRow(i,item.Name,item.Quantity.ToString(),item.Price.ToString(),item.Price.ToString());我++;}reportDataSourceSales.Value=dataset.CurrentSales;reportViewerSales.LocalReport.DataSources.Add(reportDataSourceSales);数据集.EndInit();reportViewerSales.RefreshReport();reportViewerSales.RenderingComplete+=newRenderingCompleteEventHandler(PrintSales);这是我的冲洗完成方法publicvoidPrintSales(objectsender,RenderingCompleteEventArgse){try{reportViewerSales.PrintDialog();reportViewerSales.Clear();reportViewerSales.LocalReport.ReleaseSandboxAppDomain();}catch(Exceptionex){}}我只是快速浏览了我为直接打印创建的类,我想我从这个演练中得到了一些想法:PrintLocalReportingwithoutpreviewing我已经为@tezzos回答创建了一个扩展类这可能会使它更容易。使用此GistHere获取我编写的扩展类。将其包含在您的项目中。不要获取命名空间:DLocalReportreport=newLocalReport();report.ReportEmbeddedResource="你的.Reports.Path.rdlc";report.DataSources.Add(newReportDataSource("DataSet1",getYourDatasource()));report.PrintToPrinter();PrintToPrinter方法将在LocalReportLocalReport上。可能对其他人有帮助以上是C#学习教程:HowtoprintrdlcreportwithoutshowingPrintDialog()inC#inC#?如果分享的内容对你有用,需要了解更多C#学习教程,希望你多多关注——publicvoidPrintSales(objectsender,RenderingCompleteEventArgse){reportViewerSales.PrintDialog();reportViewerSales.Clear();reportViewerSales.LocalReport.ReleaseSandboxAppDomain();}catch(Exceptionex){}}本文收集自网络,不代表立场。如涉及侵权,请点击右侧联系管理员删除。如需转载请注明出处:
