C#WinForm中追加報表以及圖片的功能

来源:https://www.cnblogs.com/ZhongLgj/archive/2020/07/28/13391159.html
-Advertisement-
Play Games

效果圖片: 分步解析實現過程: 一.新建報表所需要的文件以及類: 1.新建一個WindowForm項目WindowsFormsReport; 2. 添加Entity文件夾,並添加StudentEntity.cs類; public class StudentEntity { /// <summary> ...


效果圖片:

分步解析實現過程:

一.新建報表所需要的文件以及類:

1.新建一個WindowForm項目WindowsFormsReport;

2. 添加Entity文件夾,並添加StudentEntity.cs類;

 public class StudentEntity

{

/// <summary>
/// 姓名
/// </summary>
public string StuName { get; set; }
/// <summary>
/// 年齡
/// </summary>
public string StuAge { get; set; }
/// <summary>
/// 學生住址
/// </summary>
public string StuAddress { get; set; }
/// <summary>
/// 身高
/// </summary>
public string StuHeight { get; set; }
/// <summary>
/// 體重
/// </summary>
public string StuWeight { get; set; }
/// <summary>
/// 學生電話
/// </summary>
public string StuPhone { get; set; }
}

3.添加Report文件夾,並添加Report.rdlc報表;

建好報表,打開報表,點擊界面上的數據集右擊,新建數據集,就會彈出如下界面:

點擊數據源類型,這裡我們以對象為例:

接下來,我們只需完成後,再點擊確定就可以,在報表界面進行追加列表:

往界面上追加圖片,如下操作:

1)點擊界面上的參數,右擊新建參數:

2)在界面上右擊新插入圖片,則會彈出對圖片的配置界面如下:

此處需要註意:圖片的格式

3)對使用欄位設置,如下圖參考即可:

=System.Convert.FromBase64String(Parameters!ReportParameter1.Value)

這樣如上面的圖所設置即可:

二.現在對WindowForm頁面設置:

1)選擇工具箱中報表-ReportViewer控制項,拖入界面中

2)上面的圖,畫黃色的位置,選擇上面新建的報表:

3)用代碼實現展示:這裡我用畫面啟動就載入數據:


public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}

private void Form1_Load(object sender, EventArgs e)
{

this.reportViewer1.RefreshReport();
}

private void reportViewer1_Load(object sender, EventArgs e)
{
reportViewer1.LocalReport.DataSources.Clear();

// 插入圖片設置
reportViewer1.LocalReport.EnableExternalImages = true;
Bitmap bmp = new Bitmap(Image.FromFile("E:\\C#Del\\Lianxi\\WindowsFormsReport\\QQ.jpg"));
MemoryStream msm = new MemoryStream();
bmp.Save(msm, ImageFormat.Jpeg);
byte[] bytes = msm.ToArray();

ReportParameter repter = new ReportParameter("ReportParameter1",Convert.ToBase64String(bytes));
reportViewer1.LocalReport.SetParameters(new ReportParameter[] { repter });

reportViewer1.LocalReport.DataSources.Add(new Microsoft.Reporting.WinForms.ReportDataSource("DataSet1",DataList()));
reportViewer1.RefreshReport();
}

private List<StudentEntity> DataList()
{
List<StudentEntity> wStudentEntityList = new List<StudentEntity>();
StudentEntity wStudentEntity = new StudentEntity();
wStudentEntity.StuName = "離散";
wStudentEntity.StuAddress = "十里堡10號";
wStudentEntity.StuAge = "23歲";
wStudentEntity.StuHeight = "169cm";
wStudentEntity.StuWeight = "69Kg";
wStudentEntity.StuPhone = "13011108121";
wStudentEntityList.Add(wStudentEntity);
return wStudentEntityList;
}

接下來,我們啟動下麵,效果如下:

註意:若大家有疑問,可以給我留言,大家一起交流

 


您的分享是我們最大的動力!

-Advertisement-
Play Games
更多相關文章
  • (原文鏈接:https://almirai.live/Coding/Java/ppa-install-oracle-java-11/)[https://almirai.live/Coding/Java/ppa-install-oracle-java-11/] 添加源 Ubuntu/Mint 64bi ...
  • 練習2: 題目:企業發放的獎金根據利潤提成。利潤(I)低於或等於10萬元時,獎金可提10%;利潤高於10萬元,低於20萬元時,低於10萬元的部分按10%提成,高於10萬元的部分,可提成7.5%;20萬到40萬之間時,高於20萬元的部分,可提成5%;40萬到60萬之間時高於40萬元的部分,可提成3%; ...
  • 前言 JAVA起於1995年,經過20多年的發展,在眾多語言中脫穎而出,JAVA如今已經發展成為世界第一編程語言。而且越來越多的人加入到JAVA開發的大軍中。 2014年的數據:全球的軟體開發者數量達到1850萬,其中1100萬是專業的軟體開發人員,另外750萬是開發愛好者,其中我國程式員占比是很少 ...
  • #!/usr/bin/python3# -*- coding: UTF-8 -*-import pandas as pdimport numpy as npimport matplotlib.pyplot as pltdef main(): # 創建一個列表Series,pandas會創建整形指標 ...
  • 練習1:題目:有四個數字:1、2、3、4,能組成多少個互不相同且無重覆數字的三位數?各是多少?語句: # coding: utf-8 print ('題目:有四個數字:1、2、3、4,能組成多少個互不相同且無重覆數字的三位數?各是多少?')for aa in range(1, 5): for ab ...
  • 原文:https://almirai.live/Coding/Java/JavaWeb/Basics/type/ 數據類型 基本類型 類型 占用空間(Byte) 取值範圍 byte(位元組型) 1 -128~127 short(短整型) 2 −216~216−1 int(整型) 4 −231~231− ...
  • 提起AI,大家都會先想到Python,確實Python作為一門好幾十年的老語言,上一波的AI大流行使它煥發了青春。大家用Phtyon來做AI,最主要的原因無非就是編碼量更少,很多數學和AI相關的Api都是現成的。但是隨著ML.net的問世,我們現在可以在.netcore平臺上使用比Python更少的 ...
  • 環境: Vs 2015 .net 4.5.2 源碼: public static void toScreen() { ThreadStart ts = new ThreadStart(() =>//開線程 { Screen scr = Screen.PrimaryScreen; Rectangle ...
一周排行
    -Advertisement-
    Play Games
  • Dapr Outbox 是1.12中的功能。 本文只介紹Dapr Outbox 執行流程,Dapr Outbox基本用法請閱讀官方文檔 。本文中appID=order-processor,topic=orders 本文前提知識:熟悉Dapr狀態管理、Dapr發佈訂閱和Outbox 模式。 Outbo ...
  • 引言 在前幾章我們深度講解了單元測試和集成測試的基礎知識,這一章我們來講解一下代碼覆蓋率,代碼覆蓋率是單元測試運行的度量值,覆蓋率通常以百分比表示,用於衡量代碼被測試覆蓋的程度,幫助開發人員評估測試用例的質量和代碼的健壯性。常見的覆蓋率包括語句覆蓋率(Line Coverage)、分支覆蓋率(Bra ...
  • 前言 本文介紹瞭如何使用S7.NET庫實現對西門子PLC DB塊數據的讀寫,記錄了使用電腦模擬,模擬PLC,自至完成測試的詳細流程,並重點介紹了在這個過程中的易錯點,供參考。 用到的軟體: 1.Windows環境下鏈路層網路訪問的行業標準工具(WinPcap_4_1_3.exe)下載鏈接:http ...
  • 從依賴倒置原則(Dependency Inversion Principle, DIP)到控制反轉(Inversion of Control, IoC)再到依賴註入(Dependency Injection, DI)的演進過程,我們可以理解為一種逐步抽象和解耦的設計思想。這種思想在C#等面向對象的編 ...
  • 關於Python中的私有屬性和私有方法 Python對於類的成員沒有嚴格的訪問控制限制,這與其他面相對對象語言有區別。關於私有屬性和私有方法,有如下要點: 1、通常我們約定,兩個下劃線開頭的屬性是私有的(private)。其他為公共的(public); 2、類內部可以訪問私有屬性(方法); 3、類外 ...
  • C++ 訪問說明符 訪問說明符是 C++ 中控制類成員(屬性和方法)可訪問性的關鍵字。它們用於封裝類數據並保護其免受意外修改或濫用。 三種訪問說明符: public:允許從類外部的任何地方訪問成員。 private:僅允許在類內部訪問成員。 protected:允許在類內部及其派生類中訪問成員。 示 ...
  • 寫這個隨筆說一下C++的static_cast和dynamic_cast用在子類與父類的指針轉換時的一些事宜。首先,【static_cast,dynamic_cast】【父類指針,子類指針】,兩兩一組,共有4種組合:用 static_cast 父類轉子類、用 static_cast 子類轉父類、使用 ...
  • /******************************************************************************************************** * * * 設計雙向鏈表的介面 * * * * Copyright (c) 2023-2 ...
  • 相信接觸過spring做開發的小伙伴們一定使用過@ComponentScan註解 @ComponentScan("com.wangm.lifecycle") public class AppConfig { } @ComponentScan指定basePackage,將包下的類按照一定規則註冊成Be ...
  • 操作系統 :CentOS 7.6_x64 opensips版本: 2.4.9 python版本:2.7.5 python作為腳本語言,使用起來很方便,查了下opensips的文檔,支持使用python腳本寫邏輯代碼。今天整理下CentOS7環境下opensips2.4.9的python模塊筆記及使用 ...