Neodynamic Barcode Professional 2.0 (or greater) for Windows Forms (WinControl)
Crystal Reports for .NET (any version)
Microsoft .NET Framework (any version)
Microsoft Visual Studio .NET (any version)
Now, you can put barcode images in your Crystal Reports files using Barcode Professional in a simple manner in your Windows Forms applications.
In the following sample we're going to create a Windows Application which includes a CR report and which shows barcode images into it using Barcode Professional.
For simplicity, we're going to use an XML file as the Data Source for our CR report. This XML file includes information of employees generated from the Microsoft's Northwind database sample.
Follow these steps:
Imports Neodynamic.WinControls.BarcodeProfessional
using Neodynamic.WinControls.BarcodeProfessional;
'Create a DataSet from the XML file
'REMEMBER to copy the XML file in the same location of the EXE program
Dim xmlFile As String = System.IO.Directory.GetCurrentDirectory() & "\Employees.xml"
Dim ds As New DataSet
ds.ReadXml(xmlFile)
'The XML File with the data DOES NOT include
'the BarcodeImage "column" or element we've included
'in the XML Schema file.
'So, create the BarcodeImage column
'WARNING: you must name it as you did in the XML Schema
Dim dc As DataColumn = New DataColumn("BarcodeImage", GetType(Byte()))
'Add the BarcodeImage column to the DataTable
ds.Tables(0).Columns.Add(dc)
'Create a BarcodeProfessional object to fill
'the BarcodeImage column
Dim bc As BarcodeProfessional = New BarcodeProfessional
'We're going to use Code 128 Barcode Symbology
bc.Symbology = Symbology.Code128
bc.Text = ""
bc.QuietZoneWidth = 0
bc.ForeColor = Color.FromArgb(0, 116, 232)
'Now, generate and fill barcode images
For Each dr As DataRow In ds.Tables(0).Rows
'We're going to encode the ID column
bc.Code = CType(dr("ID"), String)
dr("BarcodeImage") = bc.GetBarcodeImage(System.Drawing.Imaging.ImageFormat.Png)
Next
'Create a AccessCards report object
'and set its data source with the DataSet
Dim report As AccessCards = New AccessCards
report.SetDataSource(ds)
'Show it!
CrystalReportViewer1.ReportSource = report
//Create a DataSet from the XML file
//REMEMBER to copy the XML file as the EXE
string xmlFile = System.IO.Directory.GetCurrentDirectory()+"\\Employees.xml";
DataSet ds = new DataSet();
ds.ReadXml(xmlFile);
//The XML File with the data DOES NOT include
//the BarcodeImage "column" or element we've included
//in the XML Schema file.
//So, create the BarcodeImage column
//WARNING: you must name it as you did in the XML Schema
DataColumn dc = new DataColumn("BarcodeImage", typeof(byte[]));
//Add the BarcodeImage column to the DataTable
ds.Tables[0].Columns.Add(dc);
//Create a BarcodeProfessional object to fill
//the BarcodeImage column
BarcodeProfessional bc = new BarcodeProfessional();
//We're going to use Code 128 Barcode Symbology
bc.Symbology = Symbology.Code128;
bc.Text = "";
bc.QuietZoneWidth = 0;
bc.ForeColor = Color.FromArgb(0,116,232);
//Now, generate and fill barcode images
foreach (DataRow dr in ds.Tables[0].Rows)
{
//We're going to encode the ID column
bc.Code = (string)dr["ID"];
dr["BarcodeImage"] = bc.GetBarcodeImage(System.Drawing.Imaging.ImageFormat.Png);
}
//Create a AccessCards report object
//and set its data source with the DataSet
AccessCards report = new AccessCards();
report.SetDataSource(ds);
//Show it!
crystalReportViewer1.ReportSource = report;
That's it. Build the Windows Application and run it.
Download the XML file here:
We provide best-in-class customer service and support directly from members of our dev team! If we are available when you contact us, you will get a response in few minutes; otherwise the maximum turnaround is 24hs in most cases.