IT评测·应用市场-qidao123.com
标题:
WinForms 应用(.NET 8.0)利用ReportViewerCore.WinForms表现打印RDLC报表
[打印本页]
作者:
我爱普洱茶
时间:
2024-6-13 21:18
标题:
WinForms 应用(.NET 8.0)利用ReportViewerCore.WinForms表现打印RDLC报表
在要WinForms 应用(.NET 8.0)中,表现RDLC报表,就要利用ReportViewerCore.WinForms。原来的ReportViewer只能在.NET Framework框架下运行。
1.ReportViewerCore.WinForms 程序包阐明
SQL Server Reporting Services ReportViewer WinForms control decompiled and recompiled for .NET Core. Based on ReportViewer 15.0.1404.0
2.主要程序ReportViewerForms.cs
using Microsoft.Reporting.WinForms;
using System;
using System.Collections.Generic;
using System.Text;
using System.Windows.Forms;
namespace ReportViewerCore
{
class ReportViewerForm : Form
{
private readonly ReportViewer reportViewer;
public ReportViewerForm()
{
Text = "ReportViewerCore.WinForms示例(目标框架.NET 8.0)";
//WindowState = FormWindowState.Maximized;
this.Width = 1000;
this.Height = 600;
reportViewer = new ReportViewer();
reportViewer.Dock = DockStyle.Fill;
Controls.Add(reportViewer);
// 设置打印布局模式,显示物理页面大小
this.reportViewer.SetDisplayMode(Microsoft.Reporting.WinForms.DisplayMode.PrintLayout);
// 缩放模式为百分比,以100%方式显示
this.reportViewer.ZoomMode = Microsoft.Reporting.WinForms.ZoomMode.Percent;
this.reportViewer.ZoomPercent = 100;
}
protected override void OnLoad(EventArgs e)
{
Report.Load(reportViewer.LocalReport);
reportViewer.RefreshReport();
base.OnLoad(e);
}
private void ReportViewerForm_Load(object sender, EventArgs e)
{
}
private void InitializeComponent()
{
SuspendLayout();
//
// ReportViewerForm
//
ClientSize = new System.Drawing.Size(784, 472);
Name = "ReportViewerForm";
StartPosition = FormStartPosition.CenterScreen;
Load += ReportViewerForm_Load;
ResumeLayout(false);
}
}
}
复制代码
using Microsoft.Reporting.WinForms;
using System;
using System.Collections.Generic;
using System.IO;
using System.Text;
namespace ReportViewerCore
{
class Report
{
public static void Load(LocalReport report)
{
var items = new[] { new ReportItem { Description = "Widget 6000", Price = 104.99m, Qty = 1 }, new ReportItem { Description = "Gizmo MAX", Price = 1.41m, Qty = 25 } };
var parameters = new[] { new ReportParameter("Title", "Invoice 4/2020") };
using var fs = new FileStream("Report.rdlc", FileMode.Open);
report.LoadReportDefinition(fs);
report.DataSources.Add(new ReportDataSource("Items", items));
report.SetParameters(parameters);
}
}
}
复制代码
3.实例窗口
免责声明:如果侵犯了您的权益,请联系站长,我们会及时删除侵权内容,谢谢合作!更多信息从访问主页:qidao123.com:ToB企服之家,中国第一个企服评测及商务社交产业平台。
欢迎光临 IT评测·应用市场-qidao123.com (https://dis.qidao123.com/)
Powered by Discuz! X3.4