Click here to Skip to main content
12,552,909 members (54,357 online)
Click here to Skip to main content
Add your own
alternative version


49 bookmarked

Generating labels with barcode in C# using Crystal Reports

, 21 May 2014 CPOL
Rate this:
Please Sign up or sign in to vote.
Generating barcode labels in C# with the help of Crystal Reports for printing.

Barcodes Generator Application


A Barcode Label System is mostly used in a POS software. I tried Googling and searching in CodeProject for barcode generators, but no result.. So I created an application in C# with Crystal Reports to create printable and scannable barcodes..

This article covers:

  • Integration of Crystal Reports in C#.
  • Using Dataset in Crystal Reports.
  • Generating Barcodes in Crystal Reports.
  • Formatting Detail Section for Multiple columns.
  • Creating a Barcode Label System with less code work.

~Barcode Label System in C#~


  • Creating a Project in C#.
  • Adding a Crystal Report to the Project.
  • Formatting the Details Section for Multiple Columns and the Page Properties
  • Adding Details to the Form
  • Adding a Dataset to the Project.
  • Combining the Dataset with Crystal Reports.
  • Adding Details to the Report.
  • Alignment of the Detail
  • Intro to Barcodes.
  • Adding a Barcode to the Report.
  • The Coding
  • FAQs
  • Troubleshooting Errors..

Creating a Project in C#

First open Visual Studio and create a Project with the desired framework..

01 - Create Project

Click OK after filling the details.

Adding a Crystal Report to the Project

02 - Add Item

01 - Create Project

03 - Blank Report

05 - Alignment of Report

  • Right-click the project and navigate to -> Add -> New Item...
  • Select Crystal Report and specify a name for it.. Let's say 'BarcodeReport.rpt'. And click Add.
  • Select Blank Report and click OK
  • Make it Look like this (don't change the detail's height):

Formatting the Details Section for Multiple Columns

06 - section expert

07 -MultipleColumns

08-Page Details

09 - Page Setup

10-Page Setup Units

  • In the Crystal Reports menu, navigate to -> Report -> Section Expert.
  • Select Details and check 'Format with Multiple Columns (Until that you will not see Layout Tab)'.
  • Navigate to Layout tab and fill the details as needed..
  • In the Crystal Reports menu, navigate to -> Design -> Page Setup...
  • Fill the details as needed.. and press OK.

First Run

Press Debug (F5) and make sure your project runs with an Empty Form... If there is an error then follow the procedure below or skip the next procedure:

Like: Missing Assembly Reference

  • Open the properties of the project.
  • If the target framework is in .NET Framework 4 client, then change it to .NET Framework 4, and click Yes.

Hit Debug(F5), the error should be rectified.. If not comment..

Adding Details to the Form

  • Make basic changes to the Form.
  • Drag and drop the Crystal Report Viewer in the form.
  • Make changes to the Report Viewer
  • Click on the small button and choose the report and hit OK.

Adding a Dataset to the Project

You might have noticed a separate column for Barcode and Shop Details, I will talk about this in the FAQ section below..

  • Open Add Item as you did for Crystal Report.
  • Select dataset, give a name, and press Add. Let's give a name 'Barcodes'.
  • Drag and drop a DataTable and rename the Datatable and add columns to it.
  • Add the following columns

Combining the Dataset with Crystal Reports

  • Open Database Expert in the Report.
  • Add the created Dataset to the Report
  • Click OK.
  • Now you can see the details of the DataSet in the database field.

Adding details to the Report

  • Drag and drop the details in the report.

Alignment of the Detail

  • Make the details somewhat look like this:

Intro to Barcodes

Before we generate a barcode we should now what a barcode is and how to use it... Try searching the internet for more details.


We have to Declare the Starting Point and Ending Point to a Barcode so that the scanner can know where the barcode starts and stops. In this article, I am going to use 'Code39' Font(IDAutomationHC39M) a true-type font. The start and stop can be denoted by '*(The Value)*'. Below is an example.

An Example to Generate a Code39 Font

Let the value to encode be ABC123. The barcode must have the value '*ABC123*', where (*) is the start and stop point.. You can get more details here.

Adding Barcode to the Report

There is a link above to download the font file (which is also included in the source code and the demo).

  • Add the barcode data field to the report and arrange it and select the font as shown below.
  • Save the report and close it..

The Coding

This application uses a simple code and is easily translatable to other .NET languages..

Open the Form and use it in the Form_Load event.

Barcodes barcodeDetails = new Barcodes();
DataTable dataTable = barcodeDetails._Barcodes;

BarcodeReport Report = new BarcodeReport();
int blank_labels = 0;
int numberofLabel = 6;
for (int i = 0; i < numberofLabel; i++)
    DataRow drow = dataTable.NewRow();
    string P_name = "DETAIL" + i.ToString();
    if (blank_labels <= i)
        drow["Barcode"] = "*";
        drow["Barcode"] += P_name;
        drow["Barcode"] += "*";

        drow["ProductId"] = P_name;
        drow["Product Name"] = "Details of " + i.ToString();
        drow["Cost"] = "Rs 110" + i.ToString() + "/-";
        drow["Code"] = "ABCDE" + i.ToString();
        drow["ShopName"] = "Shop Name";


crystalReportViewer1.ReportSource = Report;


The above code is easily understandable..

  • An integer to tell the number of blank labels so that we could leave the details to Empty.
  • An integer which tells the total number labels to generate..
  • A for loop to loop the data..
  • A data row which uses the created DataTable (dataset).
  • Check about the blank labels.. (number of labels).
  • Add details to the datarow, with start and stop for the barcode field.
  • Add the datarow to the DataTable.
  • At last, add it to the report and refresh the Report Viewer.

And at last you will get something like this:


Why am I unable to see the barcode in the Report Viewer? Most often we use Open Type font (.otf), use True Type Font (.ttf) instead.

Why is shop name used in the dataset, why not in the report like parameters? Well in the case of blank labels we cannot print anything in it.

I get an error like:

What to do with this? If you are using .NET 4.0, some may experience an error like this. Replace the app.config file with the below lines:

<?xml version="1.0"?>
  <startup useLegacyV2RuntimeActivationPolicy="true">
    <supportedRuntime Version="v4.0" sku=".NETFramework,Version=v4.0" version="v4.0"/>

The error must be rectified..


If you have any questions, leave a comment, I will try to respond as quickly as possible...

Points of Interest

In this article I hope you have understood the usage of start and stop in barcodes, and generating a barcode label system.


This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


About the Author

Mohammed Owais
Software Developer
India India
'If you don't explain easily you don't understand it well enough' - My Pal (Albert Einstein)

You may also be interested in...


Comments and Discussions

QuestionFlashControlV71.dll Pin
Member 106105754-Sep-16 23:25
memberMember 106105754-Sep-16 23:25 
QuestionChange Detail section width and page setting from c# code Pin
shethgokulesh13-Apr-16 1:45
membershethgokulesh13-Apr-16 1:45 
AnswerRe: Change Detail section width and page setting from c# code Pin
Mohammed Owais22-Apr-16 1:49
professionalMohammed Owais22-Apr-16 1:49 
QuestionMessage Removed Pin
Member 1215979324-Feb-16 13:55
memberMember 1215979324-Feb-16 13:55 
QuestionCustom lables Pin
Eng. Ahmed Negm18-Feb-16 3:51
memberEng. Ahmed Negm18-Feb-16 3:51 
AnswerRe: Custom lables Pin
Mohammed Owais26-Feb-16 1:26
professionalMohammed Owais26-Feb-16 1:26 
QuestionAsking for database login Pin
Member 1200386728-Oct-15 0:16
memberMember 1200386728-Oct-15 0:16 
AnswerRe: Asking for database login Pin
Mohammed Owais5-Nov-15 0:48
professionalMohammed Owais5-Nov-15 0:48 
GeneralRe: Asking for database login Pin
Member 120038675-Nov-15 17:50
memberMember 120038675-Nov-15 17:50 
GeneralRe: Asking for database login Pin
Mohammed Owais7-Nov-15 17:37
professionalMohammed Owais7-Nov-15 17:37 
Questioncomment Pin
Member 1160963415-Apr-15 3:35
memberMember 1160963415-Apr-15 3:35 
GeneralRe: comment Pin
Mohammed Owais17-Apr-15 21:31
professionalMohammed Owais17-Apr-15 21:31 
QuestionBarcode Integration in ASP.Net Pin
r.brahma3-Dec-14 0:21
memberr.brahma3-Dec-14 0:21 
AnswerRe: Barcode Integration in ASP.Net Pin
Mohammed Owais3-Dec-14 2:46
professionalMohammed Owais3-Dec-14 2:46 
QuestionVS 2013 support Pin
Member 416585113-Nov-14 2:52
memberMember 416585113-Nov-14 2:52 
AnswerRe: VS 2013 support Pin
Mohammed Owais14-Nov-14 8:02
professionalMohammed Owais14-Nov-14 8:02 
GeneralRe: VS 2013 support Pin
Member 416585117-Nov-14 21:16
memberMember 416585117-Nov-14 21:16 
GeneralRe: VS 2013 support Pin
Mohammed Owais19-Nov-14 0:15
professionalMohammed Owais19-Nov-14 0:15 
SuggestionFree Barcode Printing Pin
Tammam Koujan12-Nov-14 3:43
professionalTammam Koujan12-Nov-14 3:43 
GeneralRe: Free Barcode Printing Pin
Mohammed Owais12-Nov-14 3:59
professionalMohammed Owais12-Nov-14 3:59 
QuestionBarcode Printing Pin
Member 1122051010-Nov-14 23:43
memberMember 1122051010-Nov-14 23:43 
AnswerRe: Barcode Printing Pin
Mohammed Owais12-Nov-14 0:45
professionalMohammed Owais12-Nov-14 0:45 
GeneralMessage Automatically Removed Pin
29-Sep-14 15:54
memberpaul000929-Sep-14 15:54 
GeneralRe: thank you Pin
Mohammed Owais30-Sep-14 3:30
professionalMohammed Owais30-Sep-14 3:30 
QuestionBars getting merged Pin
Singh.pankaj23-Sep-14 4:15
memberSingh.pankaj23-Sep-14 4:15 
AnswerRe: Bars getting merged Pin
Mohammed Owais30-Sep-14 3:35
professionalMohammed Owais30-Sep-14 3:35 
GeneralMy vote of 5 Pin
Humayun Kabir Mamun21-May-14 19:18
memberHumayun Kabir Mamun21-May-14 19:18 
GeneralRe: My vote of 5 Pin
Mohammed Owais12-Nov-14 0:54
professionalMohammed Owais12-Nov-14 0:54 
GeneralThank You Pin
sv sathish14-May-14 19:51
professionalsv sathish14-May-14 19:51 
GeneralRe: Thank You Pin
Mohammed Owais12-Nov-14 0:54
professionalMohammed Owais12-Nov-14 0:54 
Questionnice post Pin
Md.Asif Rahman4-Apr-14 13:47
memberMd.Asif Rahman4-Apr-14 13:47 
AnswerRe: nice post Pin
Mohammed Owais12-Apr-14 2:58
professionalMohammed Owais12-Apr-14 2:58 
GeneralMy vote of 1 Pin
Member 1042568225-Nov-13 16:57
memberMember 1042568225-Nov-13 16:57 
GeneralRe: My vote of 1 Pin
Mohammed Owais29-Nov-13 23:16
professionalMohammed Owais29-Nov-13 23:16 
QuestionBarcode not showing the correct number or text. Only shows the assinged string name Pin
rajasekar kalidassan19-Nov-13 18:43
memberrajasekar kalidassan19-Nov-13 18:43 
AnswerRe: Barcode not showing the correct number or text. Only shows the assinged string name Pin
Mohammed Owais21-Nov-13 0:44
professionalMohammed Owais21-Nov-13 0:44 
GeneralRe: Barcode not showing the correct number or text. Only shows the assinged string name Pin
rajasekar kalidassan21-Nov-13 1:58
memberrajasekar kalidassan21-Nov-13 1:58 
GeneralRe: Barcode not showing the correct number or text. Only shows the assinged string name Pin
Mohammed Owais23-Nov-13 0:56
professionalMohammed Owais23-Nov-13 0:56 
AnswerRe: Barcode not showing the correct number or text. Only shows the assinged string name Pin
Mohammed Owais21-Nov-13 0:50
professionalMohammed Owais21-Nov-13 0:50 
QuestionAbout Barcode Pin
Member 102993939-Nov-13 18:25
memberMember 102993939-Nov-13 18:25 
AnswerRe: About Barcode Pin
Mohammed Owais11-Nov-13 4:54
professionalMohammed Owais11-Nov-13 4:54 
SuggestionCode 128 Pin
hmdmgd313-Aug-13 14:06
memberhmdmgd313-Aug-13 14:06 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

| Advertise | Privacy | Terms of Use | Mobile
Web02 | 2.8.161021.1 | Last Updated 21 May 2014
Article Copyright 2013 by Mohammed Owais
Everything else Copyright © CodeProject, 1999-2016
Layout: fixed | fluid