How to print barcode label with TSC Printer

In C Sharp, Programming, Programming Projects by Baqir Ali

In order to print with the TSC Label printer, you should have the physical printer, as well as the driver, installed then follow the following commands or you can download the completed project from our GitHub.

  • Create a new windows form project in visual studio Named TSC Print
  • Create the following form design
TSC Label Printer
  • Open program.cs file
  • Add the following line
using System.Runtime.InteropServices;

and paste the following code before the class program as shown below

public class TSCLIB_DLL
        [DllImport("TSCLIB.dll", EntryPoint = "about")]
        public static extern int about();

        [DllImport("TSCLIB.dll", EntryPoint = "openport")]
        public static extern int openport(string printername);

        [DllImport("TSCLIB.dll", EntryPoint = "barcode")]
        public static extern int barcode(string x, string y, string type,
                    string height, string readable, string rotation,
                    string narrow, string wide, string code);

        [DllImport("TSCLIB.dll", EntryPoint = "clearbuffer")]
        public static extern int clearbuffer();

        [DllImport("TSCLIB.dll", EntryPoint = "closeport")]
        public static extern int closeport();

        [DllImport("TSCLIB.dll", EntryPoint = "downloadpcx")]
        public static extern int downloadpcx(string filename, string image_name);

        [DllImport("TSCLIB.dll", EntryPoint = "formfeed")]
        public static extern int formfeed();

        [DllImport("TSCLIB.dll", EntryPoint = "nobackfeed")]
        public static extern int nobackfeed();

        [DllImport("TSCLIB.dll", EntryPoint = "printerfont")]
        public static extern int printerfont(string x, string y, string fonttype,
                        string rotation, string xmul, string ymul,
                        string text);

        [DllImport("TSCLIB.dll", EntryPoint = "printlabel")]
        public static extern int printlabel(string set, string copy);

        [DllImport("TSCLIB.dll", EntryPoint = "sendcommand")]
        public static extern int sendcommand(string printercommand);

        [DllImport("TSCLIB.dll", EntryPoint = "setup")]
        public static extern int setup(string width, string height,
                  string speed, string density,
                  string sensor, string vertical,
                  string offset);

        [DllImport("TSCLIB.dll", EntryPoint = "windowsfont")]
        public static extern int windowsfont(int x, int y, int fontheight,
                        int rotation, int fontstyle, int fontunderline,
                        string szFaceName, string content);
    static class Program
        /// <summary>
        /// The main entry point for the application.
        /// </summary>
        static void Main()
            Application.Run(new Form1());

Now open the form click on the Print button to generate an on-click event Then paste the code

private void button1_Click(object sender, EventArgs e)
                string bName = txtBusinessName.Text;
                string pName = txtProductName.Text;
                string pCode = txtProductCode.Text;
                double price = double.Parse(txtProductPrice.Text);

                    TSCLIB_DLL.openport("Printer Name");         //Open specified printer driver
                    TSCLIB_DLL.setup("35", "25", "4", "8", "0", "2.5", "0");    //Setup the media size and sensor type info
                    TSCLIB_DLL.clearbuffer();     //Clear image buffer
                    TSCLIB_DLL.windowsfont(18, 25, 25, 0, 2, 0, "Century Gothic", bName);  //Draw Business Name
                    TSCLIB_DLL.barcode("18", "55", "128", "60", "1", "0", "2", "2", pCode); //Drawing barcode
                    TSCLIB_DLL.windowsfont(18, 135, 30, 0, 2, 0, "Century Gothic", pName);  //Draw Product Name
                    TSCLIB_DLL.windowsfont(18, 165, 30, 0, 2, 0, "Century Gothic", "Retail: Rs." + price);  //Draw Price
                    TSCLIB_DLL.sendcommand("PUTPCX 100,400,\"UL.PCX\"");  //Drawing PCX graphic
                    TSCLIB_DLL.printlabel("1", "1"); //Print labels
            catch (Exception ex)

The above code prints on TSC Printer for the 34×24 (1) up label, and you can loop over your list of products to print multiple labels at a time.

In order to download the project go to our GitHub page then click on repositories.

Download the project from our GitHub page.

Support us by sharing this post

About the Author

Baqir Ali

Facebook Twitter

Hi, I am Baqir Ali ---- Blogger, Programmer, and a Teacher. I am currently working as a Programmer for Softnat Technologies. I have tons of ideas and data to share with you all via blogging.