DataMatrix .NET Control C# Tutorial

How to use our DataMatrix .NET control from Microsoft C#.


1. Install our DataMatrix .NET Control and start Microsoft Visual Studio. Create a new project after that.

Start Microsoft Visual Studio and create a new project.

2. Register DataMatrix .NET Control in your application. Open Toolbox for that.

Register DataMatrix .NET Control in your application.

3. Right-click to open the context menu and select Customize Toolbox.

Customize Toolbox

4. Switch to the .NET Framework Components tab and click the Browse button. Then select the file Barcodes.DataMatrix.dll.

select the file Barcodes.DataMatrix.dll

5. Now the DataMatrix .NET Control is present on the Windows Forms tab. You can put it on the form.

Put DataMatrox .NET Control to form

6. Adjust the properties of the DataMatrix .NET Control.

Adjust the datamatrix .NET properties

7. Place the code for using the control.

The following code saves the datamatrix image to an image file. The datamatrix barcode will have x-dimension equal to 4 pixels.
double w, h;
dataMatrixControl1.GetMatrixSize( 4, 1, 1, Barcodes.DataMatrix.Dimensions.dmPixels,
    Barcodes.DataMatrix.Dimensions.dmPixels, out w, out h );
dataMatrixControl1.SaveToImageFile( w, h, "c:\\DataMatrix.bmp", 96,
    Barcodes.DataMatrix.Dimensions.dmPixels );
Copies the DataMatrix bar code image to the clipboard.
dataMatrixControl1.CopyToClipboard( 200, 200 );
The DataMatrix barcode can be displayed in any Graphics object or Device Context (HDC).
Graphics gr = this.CreateGraphics();
dataMatrixControl1.DrawMatrixToSize( 0, 0, 200, 200,
    Barcodes.DataMatrix.Dimensions.dmPixels, gr );
This code allows you to print the barcode on the printer.
private void button4_Click(object sender, System.EventArgs e)
	  PrintDocument pd = new PrintDocument();
	  pd.PrintPage += new PrintPageEventHandler( this.OnPrintBarcodePage );
				catch( Exception ex ) 
	  MessageBox.Show( ex.Message );
// The OnPrintBarcodePage event is raised for each page to be printed.
private void OnPrintBarcodePage(object sender, PrintPageEventArgs ev) 
				double wMM, hMM;
	dataMatrixControl1.GetMatrixSize( 1, (int)ev.Graphics.DpiX,
				out wMM, out hMM );
				// print a datamatrix barcode
	dataMatrixControl1.DrawMatrixToSize(10, 10, wMM, hMM, 
		Barcodes.DataMatrix.Dimensions.dmMM, ev.Graphics );

The installation package contains the entire example of how to use our DataMatrix .NET Control. The example is written in MS C#.