C# Barkod Yaratma Örneği

C# dilinde barkod yaratma örneği verilmiştir. Bunun için gerekli adımlara bakalım..

İlk önce bu linkten gerekli font (IDAutomationHC39M Free Version) indirilir ve yüklenir.

Daha sonra bir windows form uygulaması yaratılır. Formun içine bir Button, bir PictureBox ve bir Textbox eklenir.

Son olarak aşağıdaki kod kullanılır..

private void button1_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 Free Version", 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;
            }
}


C#

İlginizi Çekebilir

C# Bir Stringi Ters Çevirmek

C# Linq Contains Metodu

C# Bir Sayının Mutlak Değerini Alma

C# String Her Kelimenin İlk Harfini Büyük Yapma

C# Bir Dictionary'i Filtreleyip Yeni Bir Dictionary Yaratma Örneğ ...