How to insert barcode images into the Header or Footer sections of a RDLC ReportViewe


Well-known member
Dec 5, 2005
Programming Experience
- Neodynamic Barcode Professional 7.0 for .NET Windows Forms (or greater)
- Microsoft .NET Framework 3.5 (or greater)
- Microsoft Visual Studio 2010 or Visual Basic 2010 Express or Visual C# 2010 Express

In this simple guide you will learn how to insert a barcode image to the Header or Footer sections of a RDLC report in a Windows Forms application project using C# or VB.NET and Neodynamic Barcode Professional for Windows Forms.
RDLC reports are included since Visual Studio 2005 and allow you to design reports in Visual Studio which are displayed on a form by using ReportViewer controls.

- The source code in this guide was made by using Visual Studio 2010 but you can easily use it in older versions of ReportViewer controls like the ones delivered with Visual Studio 2008.
- The RDLC report in this guide has no data source settings for simplicity but the same technique shows here can be used with reports bound to any data source.

The idea is to create a Windows form allowing the user to enter a text value which will be converted to a barcode images inserting it in the Header section of a RDLC report. In this guide we'll generate a well known linear barcode called Code 128 (USS Code 128) using Neodynamic Barcode Professional for Windows Forms component based on the specified value but you could use any of the barcode standards included in Barcode Professional like Code 39, EAN-13, UPC-A, GS1-128, USPS Intelligent Mail Barcode as well as 2D symbologies like Data Matrix, QR Code, Aztec Code, PDF 417, etc. (More info about all supported barcode symbologies in Barcode Pro for Windows Forms)


The Windows Forms app sample displaying a barcode image inside the Header section of a RDLC report

Please follow up these steps:
- Download and install latest version of Neodynamic Barcode Professional for Windows Forms .NET
- Open Visual Studio and create a new Windows Forms application naming it LocalReportWithBarcodeInHeader
- Add a new RDLC Report item to your project
- With the report displayed at design time, click Report > Report Properties
In the Report Properties dialog box, click Code tab and enter the following function. Then click OK

Public Function GetBarcodeImageHeader(ByVal barcodebase64 As String) As Byte()
Return Convert.FromBase64String(barcodebase64)
End Function

- Add a new parameter to the report naming it BarcodeBinaryContent and the data type for it must be set up to Text
- With the report displayed at design time, click Report > Add Page Header
- Design your report so it looks like the following figure. In it, the main element is the Image control which will be used to display the barcode image generated by Barcode Professional


- Select the Image control on the report and in the Properties Window set the following properties:
-- MIMEType to image/png
-- Source to Database
-- Value to =Code.GetBarcodeImageHeader(Parameters!BarcodeBinaryContent.Value)
-- Sizing to AutoSize

- Add a reference to Neodynamic.WinControls.BarcodeProfessional.dll clicking Project > Add Reference...
- Open the form at design time and add a Label, a TextBox, a Button and a ReportViewer control as shown in the following figure:


- On the ReportViewer control and set up the RDLC report created above to it
- Open the form's code behind class and add this method inside it:

Visual Basic .NET
Private Sub UpdateBarcodeOnHeader()

If (Me.textBox1.Text.Trim = "") Then
MessageBox.Show("Please enter a value to encode, thanks!")
End If

Dim barcodeBase64 As String = ""

'Create an instance of Barcode Professional
Using bcp As New Neodynamic.WinControls.BarcodeProfessional.BarcodeProfessional()
'Barcode settings
bcp.Symbology = Neodynamic.WinControls.BarcodeProfessional.Symbology.Code128
bcp.BarcodeUnit = Neodynamic.WinControls.BarcodeProfessional.BarcodeUnit.Inch
bcp.BarWidth = 1.0F / 96.0F
bcp.BarHeight = 0.5F

'Set the value to encode
bcp.Code = Me.textBox1.Text
'Generate the barcode image and convert to base64 string
barcodeBase64 = Convert.ToBase64String(bcp.GetBarcodeImage(System.Drawing.Imaging.ImageFormat.Png))
End Using

'Set report parameter
Dim param As New Microsoft.Reporting.WinForms.ReportParameter("BarcodeBinaryContent", barcodeBase64, False)
Me.ReportViewer1.LocalReport.SetParameters(New Microsoft.Reporting.WinForms.ReportParameter() {param})

End Sub

private void UpdateBarcodeOnHeader()

if (this.textBox1.Text.Trim() == "")
MessageBox.Show("Please enter a value to encode, thanks!");

string barcodeBase64 = "";

//Create an instance of Barcode Professional
using (Neodynamic.WinControls.BarcodeProfessional.BarcodeProfessional bcp = new Neodynamic.WinControls.BarcodeProfessional.BarcodeProfessional())
//Barcode settings
bcp.Symbology = Neodynamic.WinControls.BarcodeProfessional.Symbology.Code128;
bcp.BarcodeUnit = Neodynamic.WinControls.BarcodeProfessional.BarcodeUnit.Inch;
bcp.BarWidth = 1f / 96f;
bcp.BarHeight = 0.5f;

//Set the value to encode
bcp.Code = this.textBox1.Text;
//Generate the barcode image and convert to base64 string
barcodeBase64 = Convert.ToBase64String(bcp.GetBarcodeImage(System.Drawing.Imaging.ImageFormat.Png));

//Set report parameter
Microsoft.Reporting.WinForms.ReportParameter param = new Microsoft.Reporting.WinForms.ReportParameter("BarcodeBinaryContent", barcodeBase64, false);
this.reportViewer1.LocalReport.SetParameters(new Microsoft.Reporting.WinForms.ReportParameter[] { param });


- Add this code to the Form_Load event handler:

Visual Basic .NET
Me.textBox1.Text = "000111222333"


this.textBox1.Text = "000111222333";


- On the form, double click on the button and add this code to the Click event handler:

Visual Basic .NET


- That's it. Run the project. Enter some value to encode and click on Refresh button so the barcode on the report's header be updated.

This Demo
More Demos
Download Barcode Professional for Windows Forms
More Information about Neodynamic Barcode Professional for Windows Forms

.NET Components & Controls
Neodynamic Barcode Professional for .NET Windows Forms
Top Bottom