场景

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();
        }

 

效果