Home:  Products:  Microsoft® Visual C# .NET Barcode FAQ & Tutorial:

Custom Barcode Windows Forms Control C# .NETMicrosoft® Visual C# .NET Barcode Integration Guide & Tutorial

IDAutomation.com provides several products and options for implementing barcodes in Visual C# .NET with flexible license agreements to meet a variety of needs including single user licenses and royalty-free developer licenses. The following chart may be used to determine the best product needed:
Product(s):     Advantages and Disadvantages:
Code 39 Barcode Fonts
  • The easiest implementation option when the specific barcode type is not important and the data consists of numbers and/or uppercase letters.
  • Data is easily formatted to the barcode font by appending asterisks to the beginning and ending of the data being encoded; no other DLLs or source code are needed.
.NET Barcode Forms Controls
  • Created exclusively for .NET Windows Applications.
  • Generates graphic barcode images without fonts.
  • Supports several linear barcode types as well as 2D symbologies including Intelligent Mail, PDF417, Data Matrix and MaxiCode barcodes.
  • Includes source code for the Barcode Image Generator written in VB.NET.
  • Purchased version is fully functional and does not require any license keys or activation.
  • All DLLs provided are signed and time-stamped with Verisign Authenticode Certificates.
  • Source code for the graphic generation library and the entire Dotnet project are provided with the purchase of the Unlimited Developer License and a signed Source Code License Agreement.
ASP.NET Barcode Web Server Controls
IDAutomation.cs C# Class File with Barcode Fonts
  • Easily integrates into the project, without the requirement for additional DLLs.
  • Supports most linear barcode types.
  • C# source code is included.
  • Methods in the class file and source code calculate the start, stop and check digits and return a character string, that when combined with IDAutomation Barcode Fonts, create a correct barcode.
Native Windows Barcode DLL with Barcode Fonts or the Universal Barcode Font
PDF417 Font and Encoder or the Data Matrix Font and Encoder
Barcode ActiveX Controls
Crystal Reports Barcode Integration When printing with Crystal Reports, refer to the Crystal Reports Barcode Integration Guide for the best implementation method.

IDAutomation.cs Class Barcode Font Integration Tutorial:

The IDAutomation.cs class file for C# encapsulates the encoding and printing of barcodes into one object. This class may be used as a template for C# barcoding needs. The class encodes data into the appropriate symbology format and sends the barcoded string to the default printer. It is important that the appropriate IDAutomation fonts are installed before attempting to call the print method of the class.

  1. Download the IDAutomation bar code C# class file and save the file to the local hard drive. It is recommended that the file be saved in the C# .NET project directory for the project it is needed for.
  2. Open the Visual Studio C# .NET project the barcode is needed for.
  3. In order to use the printing features of the IDAutomation.com class, ensure that a reference to the System.Drawing namespace exists in the C# solution. To include the System.Drawing namespace:
    • Click Project | Add Reference from the VS.NET IDE menu
    • On the .NET tab, locate and select the component name System.Drawing.dll
    • Click the Select button
    • Click the OK button
  4. Add the IDAutomation.cs file to the project:
    • Click Project | Add Existing Item from the VS.NET IDE menu

    • Navigate to the location where you saved the downloaded IDAutomation.com class file

    • Select IDAutomation.cs from the list and click Open
  5. Include the IDAutomation_FontEncoder namespace to the solution. For example:
       using IDAutomation_FontEncoder;
  6. Once the reference to the IDAutomation_FontEncoder namespace is added to the C# solution, the bar code object may be instantiated, for example:
       clsBarCode IDAutomationBarcodeObject = new clsBarCode();
    where IDAutomationBarcodeObject is the name for the instance of this bar code object. When finished using the barcode object, it is recommended to destroy the object to fee memory; for example:   
      
    IDAutomationBarcodeObject = null;
  7. Use the methods associated with the barcode object from the chart below. Methods in the class take a string as an input value, add the appropriate start and stop characters of the selected symbology, add the checksum character (if required by the symbology), and encode the data to the format of the symbology. The class also includes a print method that will take the encoded data, font type, and font size as input values and print the barcode to the default printer for the computer. The following table provides a detailed outline of each method.

Method Name Font to Use Purpose
Code128(DataToEncode) IDAutomationC128 The recommended and primary Code 128 method that will automatically encode any data from ASCII 1 to ASCII 127. This method contains many options.
Code128a(DataToEncode) IDAutomationC128 Code 128 character set A.
Code128b(DataToEncode) IDAutomationC128 Code 128 character set B.
Code128c(DataToEncode) IDAutomationC128 Code 128 character set C.
Code128HR(DataToEncode) Text Font Returns the human readable version of the data used in the Code128(DataToEncode) method.
Interleaved2of5(DataToEncode) IDAutomationI25
or
IDAutomationHI25
Formats the return string to the Interleaved 2 of 5 font.
Interleaved2of5Mod10(DataToEncode) IDAutomationI25
or
IDAutomationHI25
Performs the mod10 checksum calculation for increased accuracy and formats the return string to the Interleaved 2 of 5 font.
Code39(DataToEncode) IDAutomationC39
or
IDAutomationHC39
Formats the output to print using Code 39 fonts.
Code39mod43(DataToEncode) IDAutomationC39
or
IDAutomationHC39
Performs the mod43 checksum calculation for increased accuracy and then formats the output to print using Code 39 fonts. The mod43 checksum is usually required for LOGMARS and HIBC applications.
Codabar(DataToEncode) IDAutomationCB Formats the output to print using Codabar fonts.
EAN13(DataToEncode) IDAutomationUPCEAN Enter EAN-13 with or without a check digit, add-ons are supported. If a check digit is passed in it is ignored, recalculated, and added to the encoded output. Formats output to the UPC/EAN barcode font.
EAN8(DataToEncode) IDAutomationUPCEAN Formats output to the UPC/EAN barcode font. Enter exactly 7 characters (EAN-8 without the check digit).
MSI(DataToEncode) IDAutomationMSI Formats data to the MSI font.
POSTNet(DataToEncode) IDAutomationPOSTNET
or
IDAutomationPLANET
Enter a single string of Zip, Zip + 4 or Zip + 4 + Delivery Point. The input for this method must be a number and may include dashes and spaces.
PrintBarCode(FontName, DataToEncode, FontSize) na A print routine that combines the encoded data, the name of the font, and the font size as input parameters then sends the barcode to the default printer.
UPCA(DataToEncode) IDAutomationUPCEAN Enter UPC-A with or without a check digit, add-ons are supported. Formats output to the UPC/EAN barcode font.

Using the Barcode ActiveX Control Within a C# Windows Application:

The IDAutomation Barcode ActiveX Control allows generation of Windows Enhanced Metafile images and printing from Visual Studio.NET.
  1. Purchase or download and install the Barcode ActiveX Control.
  2. Open the project and choose Project - Add Reference.
  3. Select the IDAutomation Barcode ActiveX Control from the COM components tab of the reference list. Click Select. Click OK.
  4. The following code examples use the IDAutomation Linear Barcode ActiveX Control in the object named axBarCode1:
    To print to the default printer, initiate the Print event of the .NET PrintDocument object and call the DrawImage method of the .NET Graphics object. Insert the following lines into the code at the point in which you would like to initiate the printing of the image e.g. in the click event of a command button:
        //Create a PrintDocument object
        PrintDocument pd = new PrintDocument();
        //set and create the EventHandler for printing the page.
        pd.PrintPage += new PrintPageEventHandler(pd_PrintPage);
        //This will fire off the print page event
        pd.Print();
     

    Add an Event Handler method to the solution, which is called prior to printing, that tells the printer what to print:
        //The PrintPage event is raised for each page to be printed.
        void pd_PrintPage(object sender, PrintPageEventArgs ev)
        {
            //Initialize the vertical position variable of the graphic on the page
             int yPos = 100;       
            //Initialize the left margin of the page
            int leftMargin = ev.MarginBounds.Left;
            //Print the enhanced metafile image of the bar code
            ev.Graphics.DrawImage(axBarCode1.GetEnhWMF(), leftMargin, yPos);
        }

    An image may also be saved the to a local hard drive with the following code:
    //Preface the string variable with the @ sign, so that Windows does not interpret the drive path as an escape sequence
        string SaveLoc = @"C:\temp\SavedBarCodeImage.wmf";
    To sign up for monthly updates about new products or upgrades, please click here.
        this.axBarCode1.SymbologyID = 13;
        this.axBarCode1.SaveBarCode(SaveLoc);

    Copying the image to the clipboard is only supported with IDAutomation's .NET Forms Controls.

When printing with Crystal Reports, refer to the Crystal Reports Barcode Integration Guide for the best implementation method.

 

 roduct Quick Links: [Barcode Fonts | Font Tools | Components | Label Software | Scanners | Printers | RFID | Product Index]

© Copyright 2003-2008 IDAutomation.com, Inc., All Rights Reserved. Legal Notices.  

Over 70% of Fortune 100 companies use our products to automate their businesses.