Winform中在FastReport的PreviewControl预览控件中对report控件模板中控件值进行修改

mac2022-06-30  19

场景

FastReport安装包下载、安装、去除使用限制以及工具箱中添加控件:

https://blog.csdn.net/BADAO_LIUMANG_QIZHI/article/details/100893794

Winform中使用FastReport实现简单的自定义PDF导出:

https://blog.csdn.net/BADAO_LIUMANG_QIZHI/article/details/100920681

在上面在预览中显示模板frx文件的内容,如果要是能动态设置或者是显示一些内容,应该怎样传递。

实现

首先在report的设计窗口上添加一个字体控件,Name属性为 Text7

 

 

在打印按钮的点击事件中

private void button2_Click(object sender, EventArgs e) { //获取项目目录 string baseDir = System.Windows.Forms.Application.StartupPath; //拼接模板文件目录 var reportFile = Path.Combine(baseDir, "1.frx"); //生成report对象 report1 = new FastReport.Report(); //先清理一下 report1.Clear(); //然后加载模板文件 report1.Load(reportFile); //找到 Name属性为 Text7的控件 var t = report1.FindObject("Text7") as TextObject; if (t != null) { //修改控件值 t.Text = "霸道赋值"; } //绑定预览控件 不然会弹出新的窗口 this.report1.Preview = this.previewControl1; //显示预览窗口 report1.Prepare(); report1.ShowPrepared(); }

 

效果

 

转载于:https://www.cnblogs.com/badaoliumangqizhi/p/11535294.html

相关资源:FastReport模板编辑程序(附源码)
最新回复(0)