C#WinForm调用StiReport报表控件,实现打印模板格式自主设计、保存、预览、打印功能
|
admin
2024年12月27日 21:43
本文热度 108
|
下面给大家分享一套基于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 编辑过