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

相关推荐
hixiong1238 小时前
C# OpenvinoSharp使用RAD进行缺陷检测
开发语言·人工智能·c#·openvino
InCerry9 小时前
C# .NET 周刊|2026年2月4期
c#·.net周报·.net周刊
刘欣的博客10 小时前
C# 发送飞书webhook消息
c#·飞书·发消息
wearegogog12313 小时前
C# Modbus 协议实现
开发语言·c#
bugcome_com14 小时前
C# 泛型(Generic)完全指南:从基础到高级应用
c#
我是唐青枫14 小时前
C#.NET Memory 深入解析:跨异步边界的内存视图与高性能实战
开发语言·c#·.net
人工智能AI技术14 小时前
AI Gateway 实战:基于 C# 与 YARP 构建多模型统一接入与路由网关
人工智能·c#
njsgcs18 小时前
solidworks 导出dwg 带映射模板 c# 图纸比例一比一导出
c#·solidworks
人工智能AI技术19 小时前
美团“问小团”同款架构:C# + ASP.NET Core 搭建本地生活 AI 搜索
人工智能·c#
!chen20 小时前
C# + ViewFaceCore 快速实现高精度人脸识别
开发语言·c#