Tutorial: Inserting a dynamically created Barcode control into TX Text Control

While the tutorial uses a visual instance of TXBarcodeControl on a form, this sample shows how to add a dynamically created TXBarcodeControl to the BarcodeCollection of TX Text Control.

The source code is contained in the following directories:

1. Creating the project and controls

Start Visual Studio .NET and create a new project. Select either Visual Basic or C# as a project type, and Windows Application as a template.

Find the TX Text Control 19.0 toolbox tab that has been created automatically. All usable TX Text Control controls or components are listed in this tab.

Click on the TextControl icon and draw it on the form.

Choose Add Reference... from the main menu Project to open the Reference Manager dialog. Select Assemblies -> Extensions and find the TXBarcode assemblies TXBarcode and TXBarcode.Windows.Forms. Check both and confirm with OK.

In the Solution Explorer, open the licenses.licx which is located in the project's Properties. Add the following string:

TXTextControl.Barcode.TXBarcodeControl, TXBarcode.Windows.Forms, Version=2.0.100.500, Culture=neutral, PublicKeyToken=6b83fe9a75cfb638

Add a MenuStrip to the form and add the menu Insert with a submenu item Barcode to this MenuStrip.

Double-click the just created submenu item Barcode to insert the Clicked event handler.

Add the following code to the Click procedure of the menu item:

[C#]
private void barcodeToolStripMenuItem_Click(object sender, EventArgs e)
{
	TXTextControl.Barcode.TXBarcodeControl txBarcode1 =
		new TXTextControl.Barcode.TXBarcodeControl();

	txBarcode1.BarcodeType =
		TXTextControl.Barcode.TXBarcode.BarcodeType.QRCode;
	txBarcode1.UpperTextLength = 19;
	txBarcode1.Text = "www.textcontrol.com";

	TXTextControl.DataVisualization.BarcodeFrame bf =
		new TXTextControl.DataVisualization.BarcodeFrame(txBarcode1);

	textControl1.Barcodes.Add(bf, -1);
}
[Visual Basic]
Private Sub barcodeToolStripMenuItem_Click(sender As Object, e As EventArgs)
	Dim txBarcode1 As New TXTextControl.Barcode.TXBarcodeControl()

	txBarcode1.BarcodeType = TXTextControl.Barcode.TXBarcode.BarcodeType.QRCode
	txBarcode1.UpperTextLength = 19
	txBarcode1.Text = "www.textcontrol.com"

	Dim bf As New TXTextControl.DataVisualization.BarcodeFrame(txBarcode1)

	textControl1.Barcodes.Add(bf, -1)
End Sub

Start the application, open the main menu and choose Barcode from the Insert menu. A new TXBarcodeControl is created dynamically, it's type is set to QRCode and the Text is set. Finally, the barcode is added to TextControl's BarcodeCollection.