IDAutomation.com, Inc.

The Source for Quality Symbology

[IDAutomation.com Home Page]

 
Home: Products: Barcode Components: Free .NET Forms Control DLL: User Manual and Tutorial
 

IDAutomation Free .NET Windows Forms Control & DLL

The Freeware .NET Barcode Forms Control DLL may be used by individuals and organizations that have a gross annual revenue of less than $500,000 USD or are classified as nonprofit for tax purposes, excluding government and military organizations. This product may also be freely used by educational organizations, such as schools and universities. This freeware license is granted in the Free License section of our License Agreement. Any other use requires a purchase of our Windows .NET Forms Control to remain properly licensed.

The free .NET Barcode Forms Control supports Code 39 and Extended Code 39. The standard version includes all the other popular barcode types including UPC, EAN, Code 128, Interleaved 2 of 5 and Postnet. All other functionality of the control is the same.

INDEX:

Forms Control Tutorial

Using our controls is a simple 3 step process:


Step 1 - download and unzip the control package

Download and unzip the package. We suggest placing the DLL in a local directory such as C:\IDAutomation that is easy to remember and locate.


Step 2 - register the control in the application

After the control is installed, the application must know where it is located. We have examples below that should help with different methods of using and printing the images.

Registering the Control in Microsoft® Visual Basic .NET and Microsoft® C# .NET:

  1. Open the solution or project and display the form to which the barcode will be added. Choose View - Toolbox to display the Toolbox. Right-click on the Toolbox and choose Customize Toolbox. Choose the .NET Framework Components folder. Choose Browse and select the IDAutomation Linear Barcode Control.
  2. After the control appears in the Toolbox, add it to the form.
  3. Or choose Project - Add Reference to bypass adding it to the form.

Registering the Control in a Borland Delphi for Microsoft® .NET or C# Builder:

  1. Open the project. Choose Component - Installed .NET Components from the menu. The Installed .NET Components dialog will appear.
  2. Ensure that the Installed .NET Components tab is selected and then click on the Select an Assembly button.
  3. Navigate to the location where the IDAutomation.com Forms Control was installed.
  4. Click Open and select the control.
  5. Click OK on the Installed .NET Components dialog.
  6. The barcode control will be in the General section of the Tools Palette.

Sizing the control:

The control cannot be sized manually because it must meet specific requirements, such as a precise X dimension (narrow bar width) and barcode height specified in the properties of the control. To increase the width, increase the XDimensionCM or XDimensionMILS property. To increase the height, increase the BarHeightCM property.

Printing from the control:

  • To print the barcode or copy it to an image control, please look at the examples provided in the ZIP file or view the sample code below.
  • NOTE: When printing with the Picture method, be sure to call RefreshPrinterDPI( ) if switching printers in the application. It is recommended to call RefreshPrinterDPI( ) before each print job. We do not recommend calling RefreshPrinterDPI( ) every time the barcode itself is printed though, because it takes about .5 seconds to execute.
  • Before using PrintDocument, it is necessary to import System.Drawing.Printing as in the following VB.NET example:
    Import System.Drawing.Printing to print barcodes from your project in VB .NET
     
  • This is a simple example of printing a barcode to a user-specified printer and creating the barcode based on the resolution of the selected printer in VB.NET:
    Private Sub cmdPrint_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmdPrint.Click
     
      Dim pd as new System.Windows.Forms.PrintDialog()
      pd.PrinterSettings = new System.Drawing.Printing.PrinterSettings()
      If DialogResult.OK = pd.ShowDialog(Me) Then  'Show print dialog box
        Dim prndoc As System.Drawing.Printing.PrintDocument = New System.Drawing.Printing.PrintDocument()
        prndoc.PrinterSettings.PrinterName = pd.PrinterSettings.PrinterName
        Barcode1.ResolutionPrinterToUse = pd.PrinterSettings.PrinterName    'Tell the barcode control which printer to reference for resolution
        prndoc.DocumentName = "Printing a Barcode"
        AddHandler prndoc.PrintPage, New System.Drawing.Printing.PrintPageEventHandler(AddressOf PrintDocumentOnPrintPage)
        prndoc.Print()
      End If

    End Sub

    Private Sub PrintDocumentOnPrintPage(ByVal sender As Object, ByVal ppea As System.Drawing.Printing.PrintPageEventArgs)

      Dim grfx As System.Drawing.Graphics = ppea.Graphics
      Dim myImage As System.Drawing.Imaging.Metafile
      grfx.PageUnit = GraphicsUnit.Millimeter
      grfx.PageScale = 1.0F
      grfx.DrawString(Me.Text, Me
    .Font, Brushes.Black, 0, 0)
      myImage = Barcode1.Picture
      grfx.DrawImage(myImage, 0, 20)

    End Sub
     

  • This is a simple example of how to send the barcode metafile to a PictureBox in VB .NET:
    Private Sub cmdDisplayMetafile_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmdDisplayMetafile.Click
      Dim myImage As System.Drawing.Imaging.Metafile
      myImage = Barcode1.Picture
      Dim grfx As System.Drawing.Graphics = PictureBox1.CreateGraphics()
      grfx.DrawImage(myImage, 0, 0)
      grfx.Dispose()
      myImage = Nothing
      grfx = Nothing
    End Sub

     
  • This is a simple example of how to print the barcode using C#.NET:
    private void cmdPrint_Click(object sender, System.EventArgs e)
    {
      PrintDocument prndoc = new PrintDocument();
      prndoc.DocumentName = "Printing a Barcode";
      prndoc.PrintPage += new System.Drawing.Printing.PrintPageEventHandler(this.PrintDocumentOnPrintPage );
      prndoc.Print();
    }
    private void PrintDocumentOnPrintPage(object sender, PrintPageEventArgs ppea )
    {
      Graphics grfx = ppea.Graphics;
      System.Drawing.Imaging.Metafile myImage;
      grfx.DrawString(this.Text, this.Font, Brushes.Black, 0, 0);
      Barcode1.RefreshPrinterDPI(); //Normally you should only call RefreshPrinterDPI for each print job.
      myImage = barcode1.Picture;
      grfx.DrawImage(myImage, 0, 40);
      return;
    }
     
  • This is a simple example of how to print the barcode using Borland's C#Builder:
    private void button1_Click(object sender, System.EventArgs e)
    {
      //This is the event handler to print the image of this barcode on the printer
      //Create the document object that we are sending to the printer
      System.Drawing.Printing.PrintDocument prndoc = new System.Drawing.Printing.PrintDocument();

      //Give the document a title. This is what displays in the Printers Control Panel item
      prndoc.DocumentName = "Printing a Barcode";

      //Add an event handler to handle any additional processing that may need to occur, such as positioning of text
      prndoc.PrintPage += new System.Drawing.Printing.PrintPageEventHandler(this.PrintBMPOnPrintPage);

      //Initiate the printing of the page. PrintDocumentOnPrintPage will be handled next
      prndoc.Print();

    } //End Button_Click event

    private void PrintBMPOnPrintPage(object sender, System.Drawing.Printing.PrintPageEventArgs ppea)
    {
      //This will send the bitmap to the printer.
      System.Drawing.Graphics grfx = ppea.Graphics; //Create a Graphics Object
      System.Drawing.Image MyImage; //Create the image object
      MyImage = barcode1.BMPPicture; //Set the image object

      //Draw everything on the Graphics object and then dispose of it
      grfx.DrawString("Printing barcode using the bitmap image", this.Font, Brushes.Black, 0, 0);
      grfx.DrawImage(MyImage, 2, 40);
      grfx.Dispose();
      MyImage = null;
    }

Dynamically placing the control on a form:

  • This is how the barcode can be created on the form with code. The code in the printing example above may be used to print the image instead of sending it to a picturebox.

Dim NewBarcode As IDAutomation.Windows.Forms.LinearBarCode.Barcode = New Barcode()
NewBarcode.Size = New System.Drawing.Size(148, 64)
NewBarcode.Location = New System.Drawing.Point(176, 7)
NewBarcode.Name = "NewBarcode"
Me.Controls.AddRange(New System.Windows.Forms.Control() {NewBarcode})
NewBarcode.DataToEncode = "999928829"
PictureBox1.Image = NewBarcode.Picture

  • This is how the barcode can be created on the form using Borland's C# Builder.

//Create the new barcode object
IDAutomation.Windows.Forms.LinearBarCode.Barcode NewBarcode = new IDAutomation.Windows.Forms.LinearBarCode.Barcode();
NewBarcode.Location = new System.Drawing.Point(1, 1); //Set the location to the top left corner
NewBarcode.Name = "NewBarcode"; //Give the barcode a name
this.Controls.AddRange(new System.Windows.Forms.Control[] { NewBarcode }); //add the barcode to the controls collection
NewBarcode.DataToEncode = "123ABC78"; //Update the Data
NewBarcode.RefreshImage();//Since there is not a paint event, update the images

Using the control as a DLL or in a Web Service Application (creates a barcode image without installing it on a form):

  • The code in the printing example above may be used to print the image instead of sending it to a picturebox.

Dim NewBarcode As IDAutomation.Windows.Forms.LinearBarCode.Barcode = New Barcode()
NewBarcode.DataToEncode = "999928829"
PictureBox1.Image = NewBarcode.Picture

Creating JPEG, TIFF, BMP, PNG or other graphic files:

  • Since our control uses the .NET framework to perform image conversion, a barcode image may be created in any format that .NET supports in System.Drawing.Imaging.ImageFormat. Remember to set the DPI when creating images as in the example below. When creating barcodes for the web browser, 96 DPI is the recommended setting.

Barcode1.Resolution = Barcode.Resolutions.Custom
Barcode1.ResolutionCustomDPI = 300
Barcode1.XDimensionCM = 0.03
Barcode1.SaveImageAs("SavedBarcode300DPI.Jpeg", System.Drawing.Imaging.ImageFormat.Jpeg)
Barcode1.Resolution = Barcode.Resolutions.Printer

  • Using Borland's C# Builder for .NET

//The following is an example of changing the resolution of the barcode object and saving the image as a JPEG.
barcode1.Resolution = IDAutomation.Windows.Forms.LinearBarCode.Barcode.Resolutions.Custom; //Define the own resolution size
barcode1.ResolutionCustomDPI = "300"; //Set the resolution
barcode1.XDimensionCM = "0.03"; //Set the X Dimension

//Here's where the file is saved. If a full path is not specified, the file is created in
//the same directory as the IDAutomation.LinearBarcode.DLL.
barcode1.SaveImageAs("SavedBarcode300DPI.Jpeg", System.Drawing.Imaging.ImageFormat.Jpeg);
barcode1.SaveImageAs(@"C:\SavedBarcode300DPI.Tiff", System.Drawing.Imaging.ImageFormat.Tiff);
barcode1.Resolution = IDAutomation.Windows.Forms.LinearBarCode.Barcode.Resolutions.Printer; //Reset the resolution to the default printer's DPI

Copying barcodes to the clipboard:

  • Use the BMPPicture method to obtain an image that can be sent to the clipboard. The Picture method may also be used, however, it will only paste from the clipboard accurately into applications when using the 1.1 version of the .NET Framework.

Dim datobj As New System.Windows.Forms.DataObject()
Dim MyBitmap As New System.Drawing.Bitmap(Maxicode1.BMPPicture)
datobj.SetData(System.Windows.Forms.DataFormats.Bitmap, MyBitmap)
System.Windows.Forms.Clipboard.SetDataObject(datobj)
MyBitmap = Nothing
datobj = Nothing


Step 3 - adjust the properties of the control

After the control is inserted in the application as described in step 2, the properties can be adjusted in the control. To do this, the properties can be changed with program code or by right-clicking on the control and choosing Properties if it is loaded on a form.

NOTE: Many of the barcode sizing parameters are calculated in CM (centimeters). Please refer to the following rules for conversions:

  • To convert mils to CM, multiply the mils value by .00254. For example, 12 mils * .00254 = .03 CM.
  • To convert CM to mils, divide the CM value by 2.54. For example, .03 CM / 2.54 = 11.8 mils.
  • To convert inches to CM, multiply the value in inches by 2.54.
Linear Properties:
This section explains the main configuration parameters and methods of the linear control.
For advanced properties, please refer to the API Documentation.
  • DataToEncode - the data that is to be encoded in the barcode.
  • SymbologyID - the default in this free version is Code 39. For more information on barcode types, visit our barcoding for beginners site.
  • BarHeightCM - the height of the barcode in CM. Default is 1 CM. 2.54 CM = 1 inch.
  • LeftMarginCM - the space of the left margin in CM.
  • XDimensionCM - width in centimeters of the narrow bars. The default is 0.03 CM which is about .012" or 12 mils. This value may be increased if the scanner cannot read barcodes with small X dimensions. When working with a high quality scanner, this value can be decreased to obtain a higher density barcode.
  • XDimensionMILS - the width in mils (1/1000 of an inch) of the narrow bars.
  • BMPPicture - use the BMPPicture method to obtain an image that can be sent to the clipboard. The Picture method may also be used, however, it will only paste from the clipboard accurately into applications when using the 1.1 or greater version of the .NET Framework. See an example...
  • CaptionAbove - text that can be placed above the barcode.
  • CaptionBelow - text that can be placed below the barcode.
  • CharacterGrouping – determines the number of characters between spaces in the text interpretation of the data encoded in the barcode. Default =0 (off); supported values are 3, 4 and 5.
  • CheckCharacter - automatically adds the check digit to the barcode. Default = False
  • CheckCharacterInText - automatically adds the check digit that is encoded in the barcode to the human readable text that is displayed. Default = True
  • BearerBarHorizontal - determines the horizontal bearer bar width. The value is a multiple of the X Dimension. Default = 0.
  • BearerBarVertical - determines the vertical bearer bar width. The value is a multiple of the X Dimension. Default = 0.
  • Font - the font of the text in the barcode.
    To change the font in code, use the following syntax for VB .NET:
    Barcode1.Font = New Font(New FontFamily("Arial"), 14)
    To change only the point size in code, use the following syntax for VB.NET:
    Barcode1.Font = New Font(Barcode1.Font.FontFamily, 14)
  • FitControlToBarcode - if true, this property will automatically size the control canvas to fit the barcode at design or runtime.
  • IndependentEMF - the property used to retrieve a device independent metafile image. For example: myImage = Barcode1.IndependentEMF - see the VB source code example for more information. NOTE: It is suggested that the Picture method be used when printing to printers with less than 600 DPI.
  • NarrowToWideRatio - this is the wide to narrow ratio of symbologies that only contain narrow and wide bars. Usually, this value is between 2 and 3. The default value is 2.
  • RotationAngle - indicates the orientation of the barcode. Valid values are 0 (normal), 90 (vertical),180 (inverted) and 270 (inverted vertical).
  • Picture - this property is used to retrieve the metafile image that is calculated according to Resolution. It is suggested that this be used when printing to printers with less than 600 DPI. This property creates the EMF with the resolution information for very precise printing. Should be used with the RefreshPrinterDPI() method. See an example...
  • Resolution - the source that is used to determine the resolution the image is drawn to, which creates a more accurate barcode. Default is printer. If custom is selected, the number residing in the ResolutionCustomDPI property will determine the resolution.
  • ResolutionPrinterToUse - the property used to get the resolution for the images based off a specific printer in the printer list. This allows printing to a printer that is not the default. Invalid printer names passed into this function will be ignored. A developer can retrieve the list of valid printer name string values by checking the installed printers collection. The following C# code snippet loops through all installed printers on a machine and writes the names of the printers to the console:
    foreach(string pkInstalledPrinters in PrinterSettings.InstalledPrinters)
    {Console.Write("Installed printer name is " + pkInstalledPrinters + (char)10);}
  • ShowText - if this value is yes or true, the human readable text will be displayed with the barcode.
  • ShowTextLocation - the human-readable text can be placed above or below the barcode. Default is below.
  • TextMarginCM - the distance between the lower portion of the barcode and the text.
  • TopMarginCM - the top margin in CM.
  • WhiteBarIncrease – the percentage of increase of the white bars compared to black bars. This property may by used when a printer prints darker than normal to increase the amount of white space between bars and improve readability. Recommended values are 15% to 25% for ink jet printers. Default = 0 (no increase).

Methods:

  • SaveImageAs (filename as string, format as ImageFormat) - this method allows the barcode object to be saved as an image, such as JPEG, GIF, TIFF or PNG file. It also allows for conversion to any image type that the framework supports, for example:
    Barcode1.SaveImageAs("SavedBarcode.png", System.Drawing.Imaging.ImageFormat.Png)
  • RefreshPrinterDPI() - this method should be called every time the default printer has changed when printing with the Picture method. When printing to a printer that is not the default, the ResolutionPrinterToUse property should be set first. This sets Barcode.Resolutions.Printer to the printer's resolution. It is recommended that RefreshPrinterDPI( ) is called just before each print job. We do not recommend calling RefreshPrinterDPI( ) every time the barcode itself is printed because it takes about .5 seconds to execute.

Other products we offer:

We also have many other products to offer for barcoding purposes including:


Technical support

Free product support may be obtained by reviewing articles that are documented at our forms control support website and by searching our resolved public help desk issues. Because this is a free product we cannot offer additional support. Priority phone, email and help desk support may be obtained by ordering a license to the Standard Windows .NET Forms Control.


For additional products, please view our product index to obtain a list of all products we offer.

 

 Product Links: [Barcode Fonts | Barcode Components | Barcode Label Software | Barcode Scanners]

© Copyright 2000-2009 IDAutomation.com, Inc., All Rights Reserved. Legal Notices.

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