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

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);
        }
    }
}
cs 复制代码
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.实例窗口

相关推荐
__water6 小时前
『功能项目』QFrameWork框架重构OnGUI【63】
c#·unity引擎·重构背包框架
Crazy Struggle6 小时前
C# + WPF 音频播放器 界面优雅,体验良好
c#·wpf·音频播放器·本地播放器
晨曦_子画7 小时前
C#实现指南:将文件夹与exe合并为一个exe
c#
花开莫与流年错_7 小时前
C# 继承父类,base指定构造函数
开发语言·c#·继承·base·构造函数
hillstream38 小时前
oracle中NUMBER(1,0)的字段如何映射到c#中
数据库·oracle·c#
那个那个鱼8 小时前
.NET 框架版本年表
开发语言·c#·.net
莱茶荼菜9 小时前
使用c#制作一个小型桌面程序
开发语言·opencv·c#
Red Red10 小时前
GEO数据库提取疾病样本和正常样本|GEO数据库区分疾病和正常样本|直接用|生物信息|生信
开发语言·数据库·笔记·学习·r语言·c#·生物信息
Zhen (Evan) Wang12 小时前
What is the new in C#11?
开发语言·c#
IT规划师16 小时前
C#|.net core 基础 - 值传递 vs 引用传递
c#·.netcore·值传递·引用传递