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.实例窗口

相关推荐
爱编程的鱼2 小时前
C# 封装教程
开发语言·c#
tiegenZ3 小时前
C#接口开发异常:System.Web.HttpRequestValidationException
服务器·安全·c#
冒泡P4 小时前
C#常用LINQ
开发语言·c#·linq
佟格湾6 小时前
聊透多线程编程-线程互斥与同步-12. C# Monitor类实现线程互斥
c#·多线程
时光追逐者8 小时前
C#/.NET/.NET Core技术前沿周刊 | 第 35 期(2025年4.14-4.20)
c#·.net·.netcore
@蓝莓果粒茶9 小时前
LeetCode第158题_用Read4读取N个字符 II
前端·c++·python·算法·leetcode·职场和发展·c#
码观天工11 小时前
.NET 原生驾驭 AI 新基建实战系列(四):Qdrant ── 实时高效的向量搜索利器
c#·.net·向量数据库·qdrant
稀饭过霍11 小时前
C# .NET如何自动实现依赖注入(DI)
java·c#·.net
佟格湾11 小时前
聊透多线程编程-线程互斥与同步-13. C# Mutex类实现线程互斥
c#·多线程
全栈小512 小时前
【C#】.net core 6.0调用MVC API接口时,提示Unsupported Media Type,状态码415
c#·mvc·.netcore