C#.NET - Generate Barcode

In my Previous Article's :

  1. Speech Translator in C#.NET
  2. Datagridview Export to Excel in C#.NET
  3. Create USER Control in C#.NET

Generate Barcode in C#.NET

In these articles we see Creating barcode by using Windows Application in C#.NET. General Meaning of Barcode read below.


A machine-readable code in the form of numbers and a pattern of parallel lines of varying widths, printed on a commodity and used especially for stock control.
how can we generate and print a barcode stricker using C#
  • Before to start this Barcode Windows Application you need to "Download" and "Install" font which represents barcode language. Download Barcode Font for Free
  • After Successfully installation of barcode font, now you need to check whether the barcode font is reflected or not in Visual Studio.
    1. Right Click on Button and choose properties and select Font
    2. Open Font Windows and enter letter i in font textbox and its show similar to below image.
    3. Click Ok
    Font for Barcode | Barcode Font

C# Coding

C# Coding : Namespace

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.IO;
using System.Drawing.Imaging;

C# Coding : Get Barcode Button Click Event

namespace WindowsFormsApplication1
    public partial class generatebarcode : Form
        public generatebarcode()

        private void Btn_Generate_Click(object sender, EventArgs e)
            string barcode = textBox1.Text;
            Bitmap bitmap = new Bitmap(barcode.Length * 40, 150);
            using (Graphics ographics = Graphics.FromImage(bitmap))
                Font oFont = new System.Drawing.Font("IDAutomationHC39M", 20);
                PointF point = new PointF(2f, 2f);
                SolidBrush oblack = new SolidBrush(Color.Black);
                SolidBrush owhite = new SolidBrush(Color.White);
                ographics.FillRectangle(owhite, 0, 0, bitmap.Width, bitmap.Height);
                ographics.DrawString("*" + barcode + "*", oFont, oblack, point);
            using (MemoryStream ms = new MemoryStream())
                bitmap.Save(ms, ImageFormat.Png);
                pb_barcode.Image = bitmap;
                pb_barcode.Height = bitmap.Height;
                pb_barcode.Width = bitmap.Width;

Download Project Source Code

To Download Design and Source Code of How to Generate Barcode in C#.NET.


Post a Comment