How to generate barcode image in C# WinForms App
![barcode](https://rashicode.com/wp-content/uploads/2021/01/barcode5.png)
Create Barcode Image in c# WinForms App
In this post I’ll show you how to generate barcode image using ZXing library in C# windows Forms Application
Step 1
Open Visual Studio ,go to file ,new then project select Windows Forms Application. You can change the name of project.
![bar code](https://rashicode.com/wp-content/uploads/2021/01/barcode1-1024x540.png)
Step 2
You need to drag and drop some controls from toolbox. 1 Textbox 2 Buttons and 1 Picturebox
![barcode](https://rashicode.com/wp-content/uploads/2021/01/barcode2.png)
Step 3
Now you need to add Zxing library .Follow the steps.
1.Open Solution Explorer
2. Right Click on project
3. Select Manage NuGet Packages.
![bar code step](https://rashicode.com/wp-content/uploads/2021/01/barcode3.png)
now select Browse tab and click on search box and write “barcode” scroll down and select ZXing.net and click Install.
![bar code in c#](https://rashicode.com/wp-content/uploads/2021/01/barcode4-1024x424.png)
Step 4
Double click on both buttons to generate button Click event. Paste the following code in generate button click event.
private void btngnrte_Click(object sender, EventArgs e) { BarcodeWriter brcode = new BarcodeWriter() { Format = BarcodeFormat.CODE_128 }; pictureBox1.Image = brcode.Write(textBox1.Text); }
Paste the code below in save button click .
private void btnsave_Click(object sender, EventArgs e)
{
using (SaveFileDialog fileDialog=new SaveFileDialog() {Filter="PNG|*.png" })
{
if (fileDialog.ShowDialog()==DialogResult.OK)
{
pictureBox1.Image.Save(fileDialog.FileName);
}
}
}
Video tutorial
Source Code
Thanks for visiting us. Please don’t forget to subscribe our official YouTube Channel RashiCode