当前位置: 首页 > news >正文

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

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

相关文章:

  • 监控易监测对象及指标之:全面监控SQL Server 2008
  • shell简介
  • LLVM Cpu0 新后端4
  • linux暴力破解漏洞利用
  • 未来已来:Angular、React、Vue.js——前端框架的三大巨头
  • 【POSIX】使用iconv库将UTF-8字符串转换为UTF-16字符串
  • Pytorch环境配置
  • Mybatis06-动态SQL
  • 海康威视综合安防管理平台 多处 FastJson反序列化RCE漏洞复现
  • 【介绍下什么是Kubernetes编排系统】
  • C语言操作符详解(二)
  • 数据库练习题
  • 颠沛流离学二叉树(完结撒花篇)
  • Linux路由设置
  • 数据结构笔记2 栈和队列
  • Windows 宿主机访问 VirtualBox 虚拟机中创建的 docker 容器中的 mysql8.0 的数据
  • 基于SpringBoot的装饰工程管理系统源码数据库
  • DevOps 安全集成:从开发到部署,全生命周期安全守护
  • htb_office
  • Android --- MVVM+DataBinding+Fragment+Retrofit+Adapter 简单示例
  • 指挥家高健:东方市民音乐会“高贵不贵”,我愿意常来
  • 上海虹桥高铁站拦门事件反转,谁在带偏网友?
  • 中国医药科技出版社回应发布“男性患子宫肌瘤”论文:正在核查
  • 中东睿评|胡塞武装已成为楔入中东各方力量之间的钉子户
  • 2类药物别乱吃,严重可致肝肾衰竭!多人已中招
  • 光明日报头版评论:让投身西部成为青春潮流