Download and Install Barcode Font
First you will need to download the Free Barcode Font from the following URL
Once downloaded follow the following steps.
1. Extract the ZIP file.
2. Click and Execute INSTALL.exe file.
3. After installation is completed restart your machine.
Form Design
Add a Button, TextBox and PictureBox to the Form.
Namespaces
using System.IO;
using System.Drawing.Imaging;
Code
private void btnGenerate_Click(object sender, EventArgs e)
{
string barCode = txtCode.Text;
Bitmap bitMap = new Bitmap(barCode.Length * 40, 80);
using (Graphics graphics = Graphics.FromImage(bitMap))
{
Font oFont = new Font("IDAutomationHC39M", 16);
PointF point = new PointF(2f, 2f);
SolidBrush blackBrush = new SolidBrush(Color.Black);
SolidBrush whiteBrush = new SolidBrush(Color.White);
graphics.FillRectangle(whiteBrush, 0, 0, bitMap.Width, bitMap.Height);
graphics.DrawString("*" + barCode + "*", oFont, blackBrush, point);
}
using (MemoryStream ms = new MemoryStream())
{
bitMap.Save(ms, ImageFormat.Png);
pictureBox1.Image = bitMap;
pictureBox1.Height = bitMap.Height;
pictureBox1.Width = bitMap.Width;
}
}
Screenshot
