Windows Forms: Display Image in Report Viewer using C#
By FoxLearn 10/23/2020 10:42:05 PM 17.45K
This post shows you How to display image in RDLC Report in C# Windows Forms Application
Step 1: Click New Project, then select Visual C# on the left, then Windows and then select Windows Forms Application. Name your project "RDLCWithImage" and then click OK
Step 2: Design your form as below
Name your main form: Form1
Name your print form: frmPrint
Add a Report Viewer to your print form
You can design your report as below
Add code to handle Form1 form
public partial class Form1 : Form { public Form1() { InitializeComponent(); } string imageUrl = null; private void btnBrowse_Click(object sender, EventArgs e) { //Select an image, then display to the picturebox control using (OpenFileDialog ofd = new OpenFileDialog() { Filter = "JPEG|*.jpg" }) { if (ofd.ShowDialog() == DialogResult.OK) { imageUrl = ofd.FileName; pictureBox.Image = Image.FromFile(ofd.FileName); } } } private void btnPrint_Click(object sender, EventArgs e) { if (!string.IsNullOrEmpty(imageUrl)) { //Open print form using (frmPrint frm = new frmPrint(imageUrl)) { frm.ShowDialog(); } } } }
Add code to handle frmPrint form
public partial class frmPrint : Form { string _imageUrl; public frmPrint(string imageUrl) { InitializeComponent(); _imageUrl = imageUrl; } private void frmPrint_Load(object sender, EventArgs e) { //Read image from file, then set to report parameter FileInfo fi = new FileInfo(_imageUrl); ReportParameter pName = new ReportParameter("pName", fi.Name); ReportParameter pImageUrl = new ReportParameter("pImageUrl", new Uri(_imageUrl).AbsoluteUri); this.reportViewer1.LocalReport.EnableExternalImages = true; this.reportViewer1.LocalReport.SetParameters(new ReportParameter[] { pName, pImageUrl }); this.reportViewer1.RefreshReport(); } }
VIDEO TUTORIALS
- Windows Forms: How to Print RDLC Report without Report Viewer in C#
- Windows Forms: How to Create QR Code Report using RDLC Report in C#
- Windows Forms: Print Orders/Receipt using Report Viewer in C#
- Windows Forms: Create Report Viewer using Stored Procedure in C#
- Windows Forms: How to create a Chart / Graph using RDLC Report in C#
- Windows Forms: Print Receipt using Report Viewer in C#
Categories
Popular Posts
Visual Studio: Auto increment version
03/22/2024
What is ARM architecture?
03/11/2024