BarCodeWiz Logo

Create Data Matrix 2D Barcodes with C# in .NET WinForms

Step 1. Add a Reference to BarCodeWizFonts.DataMatrix.dll

  • Click on Project > Add Project Reference...

  • Click Browse...

  • Locate BarCodeWizFonts.DataMatrix.dll and click Add. The default location is:
    C:\Program Files\BarCodeWiz\BarCodeWiz Data Matrix Fonts\DotNet\net40 (use with .NET 4.0 or newer)
    C:\Program Files\BarCodeWiz\BarCodeWiz Data Matrix Fonts\DotNet\net20 (use with .NET 2.0 or newer)

Step 2. Add the following controls to your form:

  1. TextBox (textBox1) - text input, will be converted to barcode
  2. Button (button1) - to trigger the conversion. Set its Text property to "Encode"
  3. Label (label1) - to display the encoded barcode

Step 3. Edit the label properties

  • Set the Font to BCW_DM, 18pt
  • Set UseMnemonic to False

Step 4. Add code to convert the text to barcode

Double-click on Button1 and replace everything in the Click event with the following code.:

  

using BarCodeWizFonts.DataMatrix;

namespace MyBarcodeProject
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        private void button1_Click(object sender, EventArgs e)
        {
            DataMatrixFonts encoder = new DataMatrixFonts();
            label1.Text = encoder.Encode (textBox1.Text);
        }
    }
}

 


Project is ready