Introduction
In this article, we will learn how to generate barcode from C# windows application using QRCODE GENERATOR LIBRARY.
Background
In so many situations we need to generate the barcode images for products using C#. We can generate these barcode images and print them on the products, then after we can scan those barcode images and get the description like price, image, etc from the database.
Here I'll discuss how to generate the barcode using C#.
What Is Barcode?
Barcode or Qrcode is the technique to encode the data ex. Text, URL or etc into encoded image format to provide confidential access to the data. In shopping malls, you may see they are scanning those barcodes printed on products and then get the description of the particular product from their server database. For such kind of activity we have to generate those barcodes.
Here we will learn to generate barcode as well as QRcode images also.
Let's take a look step by step.
Step 1: Download QRCODE GENERATOR LIBRARY from onbarcode.com.
Step 2: Open Visual Studio - Create New Project - Windows Form.
Step 3: Add a reference to OnBarcode.Barcode.Winforms.dll.
Step 4: Design form with some input fields for accepting data to encode and the targeted location to save barcode generated image.
Step 5: To generate Barcode, as well as Qrcode images, write two different methods as follows.
private void GenerateBacode(string _data, string _filename)
{
Linear barcode = new Linear();
barcode.Type = BarcodeType.CODE11;
barcode.Data = _data;
barcode.drawBarcode(_filename);
}
private void GenerateQrcode(string _data, string _filename)
{
QRCode qrcode = new QRCode();
qrcode.Data = _data;
qrcode.DataMode = QRCodeDataMode.Byte;
qrcode.UOM = UnitOfMeasure.PIXEL;
qrcode.X = 3;
qrcode.LeftMargin = 0;
qrcode.RightMargin = 0;
qrcode.TopMargin = 0;
qrcode.BottomMargin = 0;
qrcode.Resolution = 72;
qrcode.Rotate = Rotate.Rotate0;
qrcode.ImageFormat = ImageFormat.Gif;
qrcode.drawBarcode(_filename);
}
Conclusion
In this way, you can generate barcode and QRcode images in C#. The output will look like bellow
Barcode:

Qrcode:


Kreiton LeePosted Oct 6, 2023, 2:24 AM
Dear sir, Could you please send the code of the dll? or how to remove the RED color text Trial?
jay singhPosted Apr 6, 2022, 11:08 AM
Invalid barcode setting is appear except any bar code or QR Code.
RS PrajapatiPosted Oct 26, 2020, 2:18 PM
Invalid barcode setting message is appear
Dinesh GabhanePosted Nov 12, 2019, 11:55 PM
Good One, Thanks for sharing
dipak kavadePosted Jan 30, 2019, 2:33 AM
Invalid barcode setting message is appear
Dipak V NakumPosted Dec 15, 2017, 5:23 AM
Is there any solutions of asp.net web application, i want to do in web application, is there any solution?
Sagar Pandurang KapPosted Dec 13, 2017, 7:00 AM
Thats awesome.Can you post for barcode reading too
Prudviraj SunkojuPosted Dec 6, 2017, 11:45 PM
It's really working fine. thanks a lot..
Ravi CPosted Oct 18, 2017, 7:14 AM
Dear sir, Could you please send the code of the dll? or how to remove the RED color text TRAIL?
Waruna ManjulaPosted Jun 30, 2017, 1:57 AM
Nice article........
forough RiiaziPosted Jun 19, 2017, 5:33 AM
I need to generate and then read these
forough RiiaziPosted Jun 19, 2017, 5:32 AM
How can read barcode
Shunmugam TharmalingamPosted Jun 17, 2017, 7:03 AM
Barcode only accepts integer not for string how can i overcome?
sures ctPosted Feb 15, 2017, 7:25 AM
One more number in addition to the given input is displayed in barcode. Why so?
sures ctPosted Feb 15, 2017, 7:22 AM
Hi..nice article..does the library has any license? can I use this free? Does it have any license expiry?
SubashPosted Jan 23, 2017, 4:43 AM
In this barcode not generated for me invalid barcode settings
SenthilKumar CPosted Nov 28, 2016, 5:38 AM
Barcode generated fine. I wondered ,how to generated image file to barcode
Pran K SahaPosted Feb 9, 2016, 8:01 AM
Barcode is very good. I need to insert more information with barcode. How do i do that
Deepak RaiPosted Feb 6, 2016, 5:46 AM
Its really helpful for me...
Jigs SavaliyaPosted Nov 17, 2015, 9:59 AM
how to decode the barcode using c# .net?
bhavin VachhaniPosted Aug 14, 2015, 6:49 AM
NON SENSE CODE ... Nothing Happening ...
Anuj PoulPosted Apr 3, 2015, 10:05 AM
Can we generate the barcode through excel file. if it will be possible then how just give mea some hints.
Anuj PoulPosted Apr 3, 2015, 10:04 AM
Hi Krishan
madhuri velidandlaPosted Dec 23, 2014, 2:21 AM
barcode is not coming just explain me the work flow with designing
bob bellPosted Oct 24, 2014, 5:35 AM
Thanks for your article of how to generate barcode and qr code images in C#.I am learning to generate qr code in c#.net,it's very useful for me.
Mukesh Kumar TiwariPosted May 4, 2014, 6:16 AM
nice article...
Tanmay NehetePosted Apr 23, 2014, 7:11 AM
can you please tell me code for how to read it through Scanner
Tanmay NehetePosted Apr 23, 2014, 7:11 AM
Thnx vey much buddy
vatsal shahPosted Apr 12, 2014, 2:56 AM
Thank a lot of...
Emmanuel KayPosted Nov 29, 2013, 5:25 AM
dis made a whole lots of sense. never regret to be with c#corner for real
Former memberPosted Oct 31, 2013, 4:24 AM
There is another C# Library for generating Barcodes, both linear and 2D, known as Aspose.Barcode for .NET. Here is the link. Try it : http://www.aspose.com/.net/barcode-component.aspx
Krishna GaradPosted Jul 22, 2013, 1:05 AM
@Prabu it works only for number not supported for alphabets. I thing the commercial licence of QRCode library supports alphabets pls do a check with.
Prabu SPosted Jul 19, 2013, 1:13 AM
sir thanks for this post and its not working on alphabets .. y?
Salman FarooquiPosted Jul 4, 2013, 4:14 AM
Friend its showing invalid barcode image for barcode
Salman FarooquiPosted Jul 4, 2013, 4:10 AM
Hi my qr code is generated but barcode is not
Msbh MalikPosted Jun 20, 2013, 8:11 AM
Awsome loved it
AthisankarPosted Apr 30, 2013, 1:35 AM
QR Code is working fine. but convert qr code as bytes sometimes "onBarcode" text will be printed on qrcode image.
Krishna GaradPosted Mar 12, 2013, 11:16 AM
What is this 1,2,3,4,5?
Krishna GaradPosted Mar 7, 2013, 12:26 PM
karthik send minimum 12 digit to generate barcode
karthik reddyeditedPosted Mar 6, 2013, 1:38 AMEdited Mar 6, 2013, 1:39 AM
good tutorial but Qrcode is working fine and barcode is not working showing an message on the image like invalid barcode settings
Krishna GaradPosted Jan 28, 2013, 1:01 AM
For windows phone take a look here. I'm not sure it will work with windows phone 7 any way try this as well @cindy on the given link how to print is also there. http://www.codeproject.com/Articles/20574/Open-Source-QRCode-Library
cindy warnereditedPosted Jan 27, 2013, 9:13 PMEdited Jan 27, 2013, 9:18 PM
Very great tutorial on how to print QR Code using C#.NET.
Dwayne McMillanPosted Jan 26, 2013, 12:03 PM
how do i integrate this qrcode into wp7?
Bunty ThakurPosted Dec 19, 2012, 9:30 PM
thank u very much dear for help
Krishna GaradPosted Nov 20, 2012, 5:19 AM
I think anil you are not able to generate the qecode or barcode. If you see above code then in GenerateBarcode method there is filename as parameter where you are generating barcode. Once you passed the required data and filename where you want to store generated barcode then you can load the generated image on your webpage.
anil babueditedPosted Nov 20, 2012, 3:36 AMEdited Nov 20, 2012, 3:36 AM
i HAVE ONE REQUIREMENT LIKE THIS PLZ TELL ME THE CODE HOW TO GENERETE QR CODE PLZ HELP ME ,i DON'T AN IDEA ABOUT GENERETE QR CODE USING ASP.NET<html> <head runat="server"> <body>COUPOUN TYPE:<asp:RadioButton ID="RadioButton1" runat="server" ForeColor="#006600" GroupName="coupon" Text="QR Code" /> Coupon value type:<asp:DropDownList ID="DropDownList1" runat="server" Height="24px" style="color: #0000FF; background-color: #66CCFF" Width="147px"><asp:ListItem>Select type of value</asp:ListItem><asp:ListItem>$</asp:ListItem><asp:ListItem>%</asp:ListItem></asp:DropDownList> Coupon value:<asp:TextBox ID="TextBox1" runat="server" Height="24px" style="color: #0000FF"></asp:TextBox> <asp:Button ID="Button1" runat="server" BackColor="#FF99CC" BorderStyle="Double" ForeColor="#003300" Height="31px" Text="Generate Coupons" /> </body></head> </html> Coupon type: check boxes/radio button with options to choose QRCode, BarCode, Coupon code Coupon value type: Drop down list with $, % Coupon value: text box to enter value Add button "Generate Coupons". On click of this buttontext box with generated coupon code to be pasted on client mobile page
Krishna GaradPosted Nov 19, 2012, 2:05 AM
saud there is no any property to type like |||||||||| Rs:200. You can arrange the allignment but.
saud ahmedPosted Nov 15, 2012, 5:23 PM
text alignment and positioning
saud ahmedPosted Nov 15, 2012, 5:23 PM
like we can edit barcode
saud ahmedPosted Nov 15, 2012, 5:23 PM
is there any property to type like this hello |||||||||| Rs:200
sreePosted Nov 2, 2012, 11:21 AM
Is there any property to write desired text above barcode..
tamer el morsiPosted Oct 20, 2012, 3:59 PM
i tried it and it's working fine... one thing else .. if i tried to print small number "123" i got a background text "on barcode" .. so how to remove it ??