In today's processes, barcodes are included everywhere: Invoices, delivery notes or admission tickets. Barcodes are used to store digital data on paper that can be acquired easily for further processing using laser-based scanners, cameras or mobile phones.

Barcodes of type TXTextControl.Barcode.TXBarcodeControl can be added to a template and merged like merge fields. Each barcode object gets a name that matches a datbase column in your data source.

This tutorial shows how to insert a barcode into a template using the shipped designer TX Text Control Words. TX Text Control X9 (Windows Forms or WPF) and TX Barcode .NET (Windows Forms or WPF) are required for this tutorial.

Creating the Template

  • Start TX Text Control Words and open the shipped sample database. Choose Load Sample Database from the Select Data Source drop-down button.

    TX Words
  • Select the table items from the Select Table drop-down button.

    TX Words
  • Insert a table with 3 columns and 1 row. Set the input position into the first table cell and insert some static text.

    Set the input position into the second table cell and insert the merge field item_no.

    TX Words
  • After the input position is set into the third cell, choose QRCode from the Illustrations ribbon group of the Insert ribbon tab.

    TX Words
  • Select the barcode object and choose Object Name from the Object Properties drop-down button that is part of the contextual Object Tools ribbon tab.

    TX Words

    In the opened dialog, type in the name of the associated field item_no.

  • Right-click the barcode object and choose Format... from the context menu. In the opened dialog box Barcode Layout, open the third tab and type in a longer text into the text box Text in order to set the maximum barcode text length. Type in: This is the maximum text length.

    TX Words

    The length of this text defines the maximum text length and the associated barcode size.

  • Select the whole table using the right-click context menu Select / Table.

    TX Words

    Click on the upper part of the Insert Merge Block button (not the drop-down part of the button) to insert a new block. A dialog is opened to insert the name of the block. Type in items and confirm with OK.

  • Click on Preview Merge Fields to see the results.

    TX Words
  • Save the template using the Internal TX Text Control Unicode Format (*.tx) to your hard-disk.

Merging the Template in Your Application

  • Open Visual Studio and create a new Windows Forms application. From the Toolbox, drag and drop an instance of TextControl, MailMerge and TXBarcodeControl to the form.

    TX Words

    Select the TXBarcodeControl on the form and delete it again by pressing {DEL}. We only need the references and the license entries in our project.

  • Select the MailMerge component in the component tray and find the TextComponent property in the Properties Window. Set the property to the TextControl instance textControl1.

    TX Words
  • Add a button to the form, double-click the button to open the event handler in order to add the following code:

    string sDBPath = @"C:\Program Files\Text Control GmbH\" +
                     @"TX Text Control 19.0.NET for Windows Forms\Samples\" +
                     @"Demo\x64\sample_db.xml";
    
    DataSet ds = new DataSet();
    ds.ReadXml(sDBPath);
    
    textControl1.Load(@"c:\template.tx",
        TXTextControl.StreamType.InternalUnicodeFormat);
        
    mailMerge1.MergeBlocks(ds);
    mailMerge1.Merge(ds.Tables["general"], false);

    You might need to change the path of the Samples folder and the path to your created sample template.

  • Compile and start the application and press the button to start the merge process.