How to generate barcode image in C# WinForms App
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.
Step 2
You need to drag and drop some controls from toolbox. 1 Textbox 2 Buttons and 1 Picturebox
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.
now select Browse tab and click on search box and write “barcode” scroll down and select ZXing.net and click Install.
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