In this FAQ and tutorial, we describe how to use our Bar Code Components and Barcode Fonts in a custom Microsoft Visual C# .NET application.
INDEX:
How to use our .NET Forms Control
Our Dotnet Barcode Windows Forms Controls are easy to use automation components that work with Visual C# .NET and any other development environments in the .NET framework. They allow the creation of barcodes that can be easily sent to the printer or to graphic images. Windows Forms Controls do not use fonts, they function like a smart graphic image. Unlike barcode fonts, Windows Forms Controls automatically compute the check digits and other required formulas to display and allow printing of high-quality barcodes. Once installed, the control can be sized and parameters can be set to meet required specifications. For specifics on implementation you may view the product page or view the user manual online.

Using our Server Control in an ASP Application
These advanced server controls allow the creation of barcodes on the Internet from your ASP web application as high quality JPEG graphic images - they do not use fonts. Once installed, the control can be sized and parameters can be set to meet required specifications. For specifics on implementation you may view the product page or view the user manual and tutorial.
Using the IDAutomation.cs class file within a C# application for printing barcode fonts:
LICENSE NOTICE: You may incorporate this source code in your application only if you own a valid license from Idautomation.com, Inc. for the associated font and the copyright notices are not removed from the source code. Redistribution of our fonts and components requires a Developer License.
The IDAutomation.cs class file encapsulates the data encoding and printing of bar codes into one object. This class should be used as a template for your C# bar coding needs. The class encodes data into the appropriate symbology format and sends the bar coded string to the default printer for the computer. It is important that you have the appropriate IDAutomation.com fonts installed on your computer before attempting to call the print method of the class.
Steps to including and using the IDAutomation.cs file in your application.
Before you start coding:
Download the IDAutomation.com bar code C# class file and save the file to your local hard drive. Please note where the file was saved to, you will need to find it later.
Create or open the Visual Studio .NET project in which you would like to include the class.
In order to use the printing features of the IDAutomation.com class you must ensure that you include a reference to the System.Drawing namespace in your 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
Add the IDAutomation.cs file to your 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
Using the IDAutomation.com class file in your VS.NET solution:
Include the IDAutomation.com namespace in your solution. Each namespace in your solution must be aware of the bar code namespace provided in the IDAutomation.com class file. The name of the name space in the IDAutomation.com class file is CSharpExample. To include this namespace in your code add the following code to your C# namespace:
using CSharpExample;
Once you have added the reference to the IDAutomation.com namespace to your C# solution, you are ready to instantiate and use the bar code object. To create the object you should add the following code to your solution, where VariableName is the name that you choose for your instance of this bar code object.
clsBarCode VariableName = new clsBarCode();
At this point you may begin to use the methods associated with your bar code object. The class includes methods that take in a string as an input value. The methods will 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 table below gives a more detailed outline of each method.
| Method Name | Method Description |
| Code128( ) | If you are not sure which Code 128 set is
for your application, then use this one. This is a "Code
128 Auto" function that will automatically encode any
data from ASCII 0 to ASCII 127. It will automatically
switch to character set C for numbers also. To encode alpha-numeric UCC/EAN-128, ASCII 202 or character E is entered as the FNC1 before each AI. For example, the UCC number of (8100)712345(21)12WH5678 should be entered as: E8100712345E2112WH5678. |
| Code128a( ) | Use the characters from set B to print characters not on the keyboard; the scanner will scan characters from set A. |
| Code128b( ) | Returns codes formatted to the Code 128 character set B. Formats output to the Code 128 barcode fonts. |
| Code128c( ) | This code128 function "interleaves" numbers into pairs for high density. |
| Code128HR( ) | Returns the human readable version of the data used in the Code128( ) method. |
| Interleaved2of5( ) | This function "interleaves" numbers into pairs for high density without check digits and formats the return string to the Interleaved 2 of 5 font. |
| Interleaved2of5Mod10( ) | Performs the mod10 checksum calculation for increased accuracy and formats the return string to the Interleaved 2 of 5 font. MOD 10 checksums are required by USPS for special services and for SSC-14 when using Interleaved 2 of 5 for that purpose. |
| Code39( ) | Formats the output to print using Code 39 fonts. |
| Code39mod43( ) | 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( ) | Formats the output to print using Codabar fonts. |
| EAN13( ) | 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( ) | Enter exactly 7 characters (EAN-8 without the check digit). Formats output to the UPC/EAN barcode font. |
| MSI( ) | Formats data to the MSI font standard |
| POSTNet( ) | Enter a single string of Zip, Zip + 4 or Zip + 4 + Delivery Point. The input for this method must be a number and can include dashes and spaces. |
| PrintBarCode( ) | Takes the encoded data, the name of the font, and the font size as input parameters then sends the barcode to the default printer. |
| UPCA( ) | Enter UPC-A with or without a check digit, add-ons are supported. Formats output to the UPC/EAN barcode font. |
After you have finished using the
barcode object that you have created, destroy the object by
using the following code where VariableName is the name
of your object:
VariableName = null;
Using the IDAutomation.com ActiveX control within a C# application:
The IDAutomation.com ActiveX control allows you to create a Windows Enhanced Metafile image or Visual Studio.NET image object of a bar code by simply updating a couple of properties. These examples will show how to save the image to a file, copy the object to the clipboard, and print the image to the default printer of the computer. A sample C# application accomplishing these tasks can be downloaded here. These examples assume that you have included an IDAutomation.com Linear Bar Code ActiveX control in your project and named the object, axBarCode1.
Saving the image to a
file:
To save an image of a Code128 barcode to the root
directory of your C:\ drive add the code below to your
solution
//You must preface the string variable with
the @ sign, so that Windows does not interpret the drive path
as an escape sequence for printing the string
string SaveLoc = @"";
//The numeric representation of the Code128
symbology
this.axBarCode1.SymbologyID = 13;
this.axBarCode1.SaveBarCode(SaveLoc);
Printing the image to the default printer:
To print the image to the default printer, you must
initiate the Print event of the .NET PrintDocument object, then
call the DrawImage method of the .NET Graphics object.
Insert the following lines into your 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 your
solution, which will be called prior to your application
printing the image. This handler tells the printer
exactly 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);
}
Copying the Enhanced Windows
Metafile Image and/or Picture Property Image to the
Clipboard:
This operation is not supported by Visual
Studio.NET. Microsoft has confirmed a bug in Visual
Studio.NET concerning placing Metafiles to the Windows
clipboard. There are two reasons for this problem 1)
.NET Metafiles have gone through some changes from previous
versions and they are not supported in current versions of the
Microsoft Office suite of products 2) There is a bug on the
.NET Framework GDI where the GDI+ has built in decoders that
support read-only functionality of the Windows Metafile
formats. The following link is a description of the bug
from Microsoft's Knowledge Base:
http://support.microsoft.com/default.aspx?scid=kb;en-us;q316563.
Since the functionality still works
as part of a Visual Studio 6 application, you can work around
this problem by creating a Visual Studio 6 wrapper DLL to
simulate the copy to clipboard functionality. The wrapper
DLL would include the IDAutomation.com ActiveX control with an
additional method called CopyToClipboard. This method
would be responsible for saving the Enhanced Windows Metafile
image to the clipboard. The wrapper DLL can then be
included in your dotnet application and all functionality will
work properly.