Install .NET Barcode Generator Windows Form Control to .NET Projects
.NET Barcode Generator Windows Form Control is built on C#.NET 2005. It is compatible with Microsoft C#.NET, VB.NET, Borland Delphi for Microsoft .NET, Visual Studio .NET Framework 2.0 or later version.
Install DLL
- Download the trial package and unzip.
- Copy OnBarcode.Barcode.WinForms.dll to your .NET project folder.
Note that you don't need to copy dll to .NET bin directory as .NET build tools will do it for you. - Add OnBarcode.Barcode.WinForms.dll to .NET project reference.
Install through NuGet
For Windows Forms, Console (.NET Framework) application
View more details here: How to download & install C# Barcode Generator library?
PM > Install-Package OnBarcode.Barcode.Generator.WinForms.Framework
View more details here: How to download & install C# Barcode Generator library?
Add .NET Windows Form Control to .NET Visual Studio Toolbox
- Right click .NET Visual Studio Toolbox, select menu Choose Items...
- In "Choose Toolbox Items" form, click button "Browse...", and select dll OnBarcode.Barcode.WinForms.dll.
- After selection, you will find four items under "Components" section: LinearWinForm, DataMatrixWinForm, PDF417WinForm, and QRCodeWinForm.
Tutorial: Create a new WinForm application with barcode generator enabled
1. Create new WinForms project
Start Visual Studio 2022 and select "Create a new project".
Select "Windows Forms App (.NET Framework)" in the dialog, and then press "Next" button.
Create a new project with name "OnBarcodeGeneratorWinFormsNetFrameworkDemo".
Now, all auto-generated files could be found in the WinForms project solution explorer.
Select "Windows Forms App (.NET Framework)" in the dialog, and then press "Next" button.
Create a new project with name "OnBarcodeGeneratorWinFormsNetFrameworkDemo".
Now, all auto-generated files could be found in the WinForms project solution explorer.
2. Install Barcode Generator Library dll
Add OnBarcode Barcode Generator C# library for WinForms framwork DLL reference "OnBarcode.Barcode.WinForms.dll".
3. Design the user interface with WinForms controls added
Use Toolbox to add controls to the form "Form1".
Change the property Size of control "Form1" to "720, 480" in the Properties window first.
List of controls to add (total 12 controls)
Step 1: add a Label control and TextBox control for data message
Change property Text of control "label1" to "Data Message:" and Location to "15, 33".
Change TextBox control name to "tbData", then set properties Text to "QRCode", Location to "125, 30", and Size to "200, 21".
Step 2: add Label and TextBoxe controls for barcode width and resolution.
Change property Text of control "label2" to "Width (inch):" and Location to "15, 62".
Change TextBox control name to "tbWidth", then set properties Text to "1.0", Location to "125, 59", and Size to "100, 21".
Change property Text of control "label3" to "Resolution (dpi):" and Location to "15, 91".
Change TextBox control name to "tbResolution", then set properties Text to "300", Location to "125, 88", and Size to "100, 21".
Now the Windows Form will be like:
Step 3: add Label and Button controls for fore color and back color.
Change property Text of control "label4" to "Fore Color:" and Location to "15, 121".
Change Button control name to "btForeColor", then set properties Text to "", and Location to "125, 117".
Change property Text of control "label5" to "Back Color:" and Location to "15, 150".
Change Button control name to "btBackColor", then set properties Text to "", and Location to "125, 146".
Form view after step 3.
Step 4: add Button and PictureBox controls for update and preview barcode on the form.
Change Button control name to "btShow", then set properties Text to "Show", and Location to "100, 225".
Change PictureBox control name to "pictureBoxPreview", then set properties Location to "331, 12", and Size to "361, 417".
Below is the final view of the Form.
Change the property Size of control "Form1" to "720, 480" in the Properties window first.
List of controls to add (total 12 controls)
- A Label with a TextBox for data message
- A Label with a TextBox for barcode width
- A Label with a TextBox for resolution
- A Label with a Button for fore color
- A Label with a Button for back color
- A Button for show barcode result
- A PictureImage
Step 1: add a Label control and TextBox control for data message
Change property Text of control "label1" to "Data Message:" and Location to "15, 33".
Change TextBox control name to "tbData", then set properties Text to "QRCode", Location to "125, 30", and Size to "200, 21".
Step 2: add Label and TextBoxe controls for barcode width and resolution.
Change property Text of control "label2" to "Width (inch):" and Location to "15, 62".
Change TextBox control name to "tbWidth", then set properties Text to "1.0", Location to "125, 59", and Size to "100, 21".
Change property Text of control "label3" to "Resolution (dpi):" and Location to "15, 91".
Change TextBox control name to "tbResolution", then set properties Text to "300", Location to "125, 88", and Size to "100, 21".
Now the Windows Form will be like:
Step 3: add Label and Button controls for fore color and back color.
Change property Text of control "label4" to "Fore Color:" and Location to "15, 121".
Change Button control name to "btForeColor", then set properties Text to "", and Location to "125, 117".
Change property Text of control "label5" to "Back Color:" and Location to "15, 150".
Change Button control name to "btBackColor", then set properties Text to "", and Location to "125, 146".
Form view after step 3.
Step 4: add Button and PictureBox controls for update and preview barcode on the form.
Change Button control name to "btShow", then set properties Text to "Show", and Location to "100, 225".
Change PictureBox control name to "pictureBoxPreview", then set properties Location to "331, 12", and Size to "361, 417".
Below is the final view of the Form.
4. Add behind code to the Form.
Select "View Code" from the menu to open the Form1.cs window.
Replace all contents in the Form1.cs file by following codes.
Replace all contents in the Form1.cs file by following codes.
using System; using System.Drawing; using System.Windows.Forms; using OnBarcode.Barcode; namespace OnBarcodeGeneratorWinFormsNetFrameworkDemo { public partial class Form1 : Form { public Form1() { InitializeComponent(); // Initial controls this.btForeColor.BackColor = Color.Black; this.btBackColor.ForeColor = Color.White; updatePictureBox(); } private void btForeColor_Click(object sender, EventArgs e) { ColorDialog colorDialog = new ColorDialog(); if (colorDialog.ShowDialog() == DialogResult.OK) { this.btForeColor.BackColor = colorDialog.Color; updatePictureBox(); } } private void btBackColor_Click(object sender, EventArgs e) { ColorDialog colorDialog = new ColorDialog(); if (colorDialog.ShowDialog() == DialogResult.OK) { this.btBackColor.BackColor = colorDialog.Color; updatePictureBox(); } } private void btShow_Click(object sender, EventArgs e) { updatePictureBox(); } private void updatePictureBox() { try { QRCode barcode = new QRCode(); barcode.DataMode = QRCodeDataMode.Auto; barcode.Data = this.tbData.Text; barcode.AutoResize = true; barcode.UOM = UnitOfMeasure.INCH; barcode.BarcodeWidth = float.Parse(this.tbWidth.Text); barcode.BarcodeHeight = float.Parse(this.tbWidth.Text); barcode.Resolution = int.Parse(this.tbResolution.Text); barcode.ForeColor = this.btForeColor.BackColor; barcode.BackColor = this.btBackColor.BackColor; // Note: Image in PictureBox would ignore resolution in Bitmap. this.pictureBoxPreview.Image = barcode.drawBarcode(); } catch { } } } }
5. Add Click event to all controls
Select "btForeColor" Button control in the Form and switch to Event tab in the Properties window, and then add Click event "btForeColor_Click".
Select "btBackColor" Button control, and then add Click event "btBackColor_Click".
Select "btShow" Button control, and then add Click event "btShow_Click".
Select "btBackColor" Button control, and then add Click event "btBackColor_Click".
Select "btShow" Button control, and then add Click event "btShow_Click".
6. It is done. Now press "Ctrl+F5" to run the project.
Screenshot for the Demo application.
Customize barcode settings and refresh the barcode image on the Windows Form.
Drag & Drop Barcode Generator Control to .NET Windows Forms
To print linear and 2D barcodes on .NET Windows Forms directly, you need use OnBarcode .NET Barcode Generator Windows Forms Control.
- Install .NET Barcode Generator Windows Forms Control.
- Add .NET Barcode Generator Windows Forms Control to your Visual Studio ToolBox.
- Drag and drop "LinearWinForm" to your Windows Form.
- Run the Windows application to view the barcodes generated on the form. To customize barcode settings, view each barcode types property settings below.
Generating & Printing Linear, 2D Barcodes in .NET Classes
You can use the component to generate barcodes in your .NET class directly.
- Add OnBarcode.Barcode.WinForms.dll to .NET project reference.
- Use the OnBarcode.Barcode.Linear class to generate linear barcodes in your C# or VB.NET class. To generate 2D barcodes, use class OnBarcode.Barcode.DataMatrix for Data Matrix barcode, OnBarcode.Barcode.PDF417 for PDF-417 barcode, OnBarcode.Barcode.QRCode for QR Code barcode.
- Add the following C# code to your .NET class:
Linear barcode = new Linear();
barcode.Type = BarcodeType.CODE39;
barcode.Data = "0123456789";
barcode.drawBarcode("C://csharp-barcode-code39.png");
