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

相关推荐
胖咕噜的稞达鸭18 分钟前
C++中的父继子承(2)多继承菱形继承问题,多继承指针偏移,继承组合分析+高质量习题扫尾继承多态
c语言·开发语言·数据结构·c++·算法·链表·c#
Dm_dotnet1 小时前
WPF应用绑定系统快捷键
c#
.NET修仙日记1 小时前
SQL Server实战指南:从基础CRUD到高并发处理的完整面试题库
面试·职场和发展·c#·.net·sql server·.net全栈经典面试题库
武文斌773 小时前
项目学习总结:CAN总线、摄像头、STM32概述
linux·arm开发·stm32·单片机·嵌入式硬件·学习·c#
sali-tec3 小时前
C# 基于halcon的视觉工作流-章46-不匀面划痕
人工智能·算法·计算机视觉·c#
数字化顾问4 小时前
从 DAG 到 Shuffle:掌握 Spark RDD 宽窄依赖的调优密码
c#·linq
Happy coder6 小时前
【avalonia教程】11字符串格式化、avalonia自带绑定值的转换
c#·avalonia
Panda__Panda13 小时前
docker项目打包演示项目(数字排序服务)
运维·javascript·python·docker·容器·c#
weixin_4569042713 小时前
基于.NET Framework 4.0的串口通信
开发语言·c#·.net
Tiger_shl15 小时前
C# 预处理指令 (# 指令) 详解
开发语言·c#