下面給大家分享一套基于WinForm+StiReport的打印控件,可以實現自定義打印模板,數據源綁定、預覽、保存、打印功能。
模板定義界面:
功能實現:
引用StiReport相關的dll:
?
項目生成:
部分代碼展示:
private void button1_Click(object sender, EventArgs e)
{
StiDesigner designer = new StiDesigner(report);
StiDesigner.SavingReport += StiDesigner_SavingReport;
report.RegData("TableVo", new WeightVo() { Code = "", Name = "" });
report.Compile();
report.Design();
}
private void StiDesigner_SavingReport(object sender, StiSavingObjectEventArgs e)
{
string outputDirectory = AppDomain.CurrentDomain.BaseDirectory;
report.Save($"{outputDirectory}\\Report.mrt");
MessageBox.Show("保存成功!");
}
private void button2_Click(object sender, EventArgs e)
{
string outputDirectory = AppDomain.CurrentDomain.BaseDirectory;
report.Load($"{outputDirectory}\\Report.mrt");
report.RegData("TableVo", new WeightVo() { Code = "001", Name = "這是一個打印測試模板" });
report.Compile();
report.Show();
}
private void button3_Click(object sender, EventArgs e)
{
string outputDirectory = AppDomain.CurrentDomain.BaseDirectory;
report.Load($"{outputDirectory}\\Report.mrt");
report.RegData("TableVo", new WeightVo() { Code = "001", Name = "這是一個打印測試模板" });
report.Compile();
report.Print();
}
閱讀原文:https://mp.weixin.qq.com/s/qtFLtSITEQJvxi3Bf35tXw
該文章在 2024/12/28 12:07:01 編輯過