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

相关推荐

  1. WinForm.NET开发】使用鼠标事件

    2024-06-09 05:42:03       62 阅读
  2. C# winform 打印Excel

    2024-06-09 05:42:03       25 阅读

最近更新

  1. docker php8.1+nginx base 镜像 dockerfile 配置

    2024-06-09 05:42:03       98 阅读
  2. Could not load dynamic library ‘cudart64_100.dll‘

    2024-06-09 05:42:03       106 阅读
  3. 在Django里面运行非项目文件

    2024-06-09 05:42:03       87 阅读
  4. Python语言-面向对象

    2024-06-09 05:42:03       96 阅读

热门阅读

  1. 自动驾驶人工智能

    2024-06-09 05:42:03       26 阅读
  2. 平滑值(pinghua)

    2024-06-09 05:42:03       25 阅读
  3. Ubuntu bash按Table不联想

    2024-06-09 05:42:03       30 阅读
  4. 素数幂变换问题

    2024-06-09 05:42:03       25 阅读
  5. html前端怎么赚钱:探索多元盈利途径

    2024-06-09 05:42:03       26 阅读
  6. 1、项目介绍:为什么要做此项目。

    2024-06-09 05:42:03       28 阅读
  7. ssh远程管理和密钥和yum源

    2024-06-09 05:42:03       27 阅读
  8. 动态规划学习

    2024-06-09 05:42:03       31 阅读
  9. 单片机毕业设计论文都些什么,章节规划

    2024-06-09 05:42:03       33 阅读
  10. leetcode-01-[704]二分查找[27]移除元素

    2024-06-09 05:42:03       38 阅读
  11. Leetcode:有效的括号

    2024-06-09 05:42:03       32 阅读