|
Using ABarcode ActiveX in Crystal Reports with Visual Studio .NET
This example assumes you already opened a new project and gone through the
preliminary steps.
Now follow these steps:
- Select Add New Item from the Project menu.
- Click the Crystal Report icon and press the Add button.

- Click OK in the first window of the Crystal Reports wizard.

- Choose the Products table from the previously created dataset.

- Drag & drop the ProductId, ProductName, and Barcode fields from the Field Explorer tab to the Detail section of the report.

- Right-click the Barcode item in the report design,
select Format Object in the context menu, and check Can Grow.
Press OK then save and close the report.

- Add a new form to the project, and drag & drop a CrystalReportViewer control into it.

- Drag & drop the ABarcodeX.Barcode control to the form, then set its Visible property to False.

- Double click the title bar on the form design to open the code window, then insert the code below in the Load event:
Visual Basic .NET
Public Class Form2
Private Sub Form2_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) _
Handles MyBase.Load
Dim ta As New DataSet1TableAdapters.ProductsTableAdapter
Dim dt As New DataSet1.ProductsDataTable
ta.Fill(dt)
For Each row As DataSet1.ProductsRow In dt.Rows
Me.AxBarcode1.ValueToEncode = row.ProductID.ToString
row.Barcode = ImageToByte(Me.AxBarcode1.GetWMF)
Next
Dim report As New CrystalReport1
report.SetDataSource(CType(dt, DataTable))
Me.CrystalReportViewer1.ReportSource = report
End Sub
End Class
Visual C# .NET
private void Form2_Load(object sender, EventArgs e)
{
DataSet1TableAdapters.ProductsTableAdapter ta =
new DataSet1TableAdapters.ProductsTableAdapter();
DataSet1.ProductsDataTable dt = new DataSet1.ProductsDataTable();
ta.Fill(dt);
Class1 cls1 = new Class1();
foreach (DataSet1.ProductsRow row in dt.Rows)
{
this.axBarcode1.ValueToEncode = row.ProductID.ToString();
row.Barcode = cls1.imageToByte(this.axBarcode1.GetWMF());
}
CrystalReport1 report = new CrystalReport1();
report.SetDataSource((DataTable)dt);
this.crystalReportViewer1.ReportSource = report;
}
- Set the new form as the Startup form in the Project properties (VB) or code it to open in Program.cs (C#),
then run the application.
The form will show the report with barcodes.

- The CrystalReportViewer control allows you to export the report in different formats
(PDF, Word, Excel and others), in which case the barcodes are also shown:

Crystal Reports report with barcodes export to PDF

Crystal Reports report with barcodes export to Excel

Crystal Reports report with barcodes export to Word
Using ABarcode ActiveX in Windows Forms
Using ABarcode ActiveX in RDLC reports
Back to Barcode ActiveX control for .NET developers
|