How to Set TopText of Barcode in WinForm

A barcode is a small image of lines and spaces that is often used in a store to reflect the description and price of a product, moreover, barcodes can be used in many other aspects in our daily life, such as tickets, medicine prescriptions, library books. In this article, I'll introduce you a way to add extra information in TopText of a barcode using Spire.Barcode in WinForm.

By default, 'E-iceblue' will be shown as TopText in a barcode if you don't request a key to remove it. Click here to see how to remove 'E-iceblue' logo in barcode. In this sample, more than one line of text will be added in TopText to replace 'E-iceblue'. Let's see detailed steps.

Step 1: Add Spire.Barcode controls to Visual Studio Toolbox.

Step 2: Create a Windows Forms project. Drag 'BarCodeControl' to your Form1. Here I changed the barcode type as EAN13.

How to Set TopText of Barcode in WinForm

Step 3: Double click 'button1' to write code. Customized TopText can be saved in BarCodeControl.TopText string.

string title = "Title: xxx" + Environment.NewLine;
string subject = "Subject: Information Technology" + Environment.NewLine;
string date = "Date: " + DateTime.Now.ToString() + Environment.NewLine;
string isbn = "ISBN: 1234567890005";
this.barCodeControl1.TopText = title + date + subject + isbn;

Step 4: Run the sample code and click 'button1' to get the new barcode. In addition, you can call BarCodeControl.SaveToFile() method to save the barcode as an image.

How to Set TopText of Barcode in WinForm

Full Code:

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.Drawing.Imaging;

namespace SetTopText
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        private void button1_Click(object sender, EventArgs e)
        {
            string title = "Title: xxx" + Environment.NewLine;
            string date = "Date: " + DateTime.Now.ToString() + Environment.NewLine;
            string subject = "Subject: Information Technology" + Environment.NewLine;
            string isbn = "ISBN: 1234567890005";
            this.barCodeControl1.TopText = title + date + subject + isbn;

        }
    }
}