This document provides a detailed step-by-step procedure for utilizing the BarcodeLib C# RDLC Report Barcode Generator library to produce and print barcode images within local reports in Windows Forms application (.net framework).
Replace all existing content in
Form1.cs with the following C# code:
using BarcodeLib.Barcode;
using BarcodeLib.Barcode.RDLCReports;
using Microsoft.Reporting.WinForms;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Drawing.Imaging;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace BarcodeLibRDLCBarcodeWinFormsDemo
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void Form1_Load(object sender, EventArgs e)
{
// Prepare report data.
DataTable dt = new DataTable();
dt.Columns.Add("Website", typeof(String));
dt.Columns.Add("Barcode", typeof(byte[]));
String site1 = "https://www.barcodelib.com";
String site2 = "https://www.google.com";
String site3 = "https://www.youtube.com";
// Create data for the 1st row in the table.
LinearRDLC barcode = new LinearRDLC();
barcode.Type = BarcodeType.CODE128;
barcode.ResizeImage = true;
barcode.ImageWidth = 300;
barcode.ImageHeight = 200;
barcode.ImageFormat = ImageFormat.Png;
barcode.Data = site1;
byte[] imgData = barcode.drawBarcodeAsBytes();
dt.Rows.Add(site1, imgData);
// Create data for the 2nd row in the table.
barcode.Data = site2;
imgData = barcode.drawBarcodeAsBytes();
dt.Rows.Add(site2, imgData);
// Create data for the 3rd row in the table.
barcode.Data = site3;
imgData = barcode.drawBarcodeAsBytes();
dt.Rows.Add(site3, imgData);
// Configure Report
this.reportViewer1.LocalReport.ReportPath = "Report1.rdlc";
this.reportViewer1.LocalReport.DataSources.Clear();
this.reportViewer1.LocalReport.DataSources.Add(new ReportDataSource("DataSet1", dt));
this.reportViewer1.RefreshReport();
}
}
}