文档彩票走势图>>Stimulsoft Reports.WinForms教程-2019>>【Stimulsoft Reports.WinForms教程】在线程中呈现报表
【Stimulsoft Reports.WinForms教程】在线程中呈现报表
【下载Stimulsoft Reports.Ultimate最新版本】
此示例显示如何在线程中呈现报表,在线程中呈现报表是在后台进程中运行的,为此,使用BackgroundWorker类:
private System.ComponentModel.BackgroundWorker backgroundWorker1; private void button1_Click(object sender, EventArgs e) { backgroundWorker1.RunWorkerAsync(); }
在backgroundWorker1_DoWork流程事件开始时,您可以卸载报表并连接数据,还应该订阅已编译的报表对象的Rendering事件:
private void backgroundWorker1_DoWork(object sender, DoWorkEventArgs e) { using (var stream = Assembly.GetExecutingAssembly(). GetManifestResourceStream("RenderInThread.Master-Detail-Subdetail.mrt")) { report.Load(stream); } DataSet data = new DataSet(); data.ReadXmlSchema("..\\..\\Data\\demo.xsd"); data.ReadXml("..\\..\\Data\\demo.xml"); report.RegData(data); report.IsRendered = false; report.Compile(); report.CompiledReport.Rendering += new EventHandler(CompiledReport_Rendering); report.Render(false); }
在CompiledReport_Rendering事件中更新表单上的文本——显示StatusString属性的值,完成线程工作后,在查看器中显示报表:
void CompiledReport_Rendering(object sender, EventArgs e) { button1.Invoke((EventHandler)delegate { button1.Text = report.StatusString; }); } private void backgroundWorker1_RunWorkerCompleted(object sender, RunWorkerCompletedEventArgs e) { report.Show(); }
示例代码的结果如下图所示: