場景
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(); }
效果