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

相关推荐
水煮庄周鱼鱼24 分钟前
C# 入门简介
开发语言·c#
软件黑马王子1 小时前
Unity游戏制作中的C#基础(6)方法和类的知识点深度剖析
开发语言·游戏·unity·c#
Nicole Potter2 小时前
请说明C#中的List是如何扩容的?
开发语言·面试·c#
gu203 小时前
c#编程:学习Linq,重几个简单示例开始
开发语言·学习·c#·linq
pchmi8 小时前
CNN常用卷积核
深度学习·神经网络·机器学习·cnn·c#
yuanpan8 小时前
23种设计模式之《组合模式(Composite)》在c#中的应用及理解
开发语言·设计模式·c#·组合模式
滴_咕噜咕噜9 小时前
C#基础总结:常用的数据结构
开发语言·数据结构·c#
万兴丶13 小时前
Unity 适用于单机游戏的红点系统(前缀树 | 数据结构 | 设计模式 | 算法 | 含源码)
数据结构·unity·设计模式·c#
程序猿多布14 小时前
C#设计模式 学习笔记
设计模式·c#
软件黑马王子20 小时前
Unity游戏制作中的C#基础(5)条件语句和循环语句知识点全解析
游戏·unity·c#