场景
FastReport安装包下载、安装、去除使用限制以及工具箱中添加控件:
https://blog.****.net/BADAO_LIUMANG_QIZHI/article/details/100893794
Winform中使用FastReport实现简单的自定义PDF导出:
https://blog.****.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();
}