Link Search Menu Expand Document

Display Barcode On Form - C#

BarCode SDK sample in C# demonstrating ‘Display Barcode On Form’

Form1.Designer.cs
��namespace DisplayBarcodeOnForm

{

    partial class Form1

    {

        /// <summary>

        /// Required designer variable.

        /// </summary>

        private System.ComponentModel.IContainer components = null;



        /// <summary>

        /// Clean up any resources being used.

        /// </summary>

        /// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param>

        protected override void Dispose(bool disposing)

        {

            if (disposing && (components != null))

            {

                components.Dispose();

            }

            base.Dispose(disposing);

        }



        #region Windows Form Designer generated code



        /// <summary>

        /// Required method for Designer support - do not modify

        /// the contents of this method with the code editor.

        /// </summary>

        private void InitializeComponent()

        {

            this.pictureBox1 = new System.Windows.Forms.PictureBox();

            this.panel1 = new System.Windows.Forms.Panel();

            this.label1 = new System.Windows.Forms.Label();

            this.label2 = new System.Windows.Forms.Label();

            ((System.ComponentModel.ISupportInitialize)(this.pictureBox1)).BeginInit();

            this.SuspendLayout();

            // 

            // pictureBox1

            // 

            this.pictureBox1.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle;

            this.pictureBox1.Location = new System.Drawing.Point(12, 36);

            this.pictureBox1.Name = "pictureBox1";

            this.pictureBox1.Size = new System.Drawing.Size(270, 270);

            this.pictureBox1.TabIndex = 0;

            this.pictureBox1.TabStop = false;

            // 

            // panel1

            // 

            this.panel1.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle;

            this.panel1.Location = new System.Drawing.Point(314, 36);

            this.panel1.Name = "panel1";

            this.panel1.Size = new System.Drawing.Size(270, 270);

            this.panel1.TabIndex = 1;

            this.panel1.Paint += new System.Windows.Forms.PaintEventHandler(this.panel1_Paint);

            // 

            // label1

            // 

            this.label1.AutoSize = true;

            this.label1.Location = new System.Drawing.Point(12, 9);

            this.label1.Name = "label1";

            this.label1.Size = new System.Drawing.Size(179, 13);

            this.label1.TabIndex = 2;

            this.label1.Text = "Show barcode in PictureBox control:";

            // 

            // label2

            // 

            this.label2.AutoSize = true;

            this.label2.Location = new System.Drawing.Point(311, 9);

            this.label2.Name = "label2";

            this.label2.Size = new System.Drawing.Size(157, 13);

            this.label2.TabIndex = 3;

            this.label2.Text = "Draw barcode on Panel control:";

            // 

            // Form1

            // 

            this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);

            this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;

            this.ClientSize = new System.Drawing.Size(599, 349);

            this.Controls.Add(this.label2);

            this.Controls.Add(this.label1);

            this.Controls.Add(this.panel1);

            this.Controls.Add(this.pictureBox1);

            this.Name = "Form1";

            this.Text = "Form1";

            ((System.ComponentModel.ISupportInitialize)(this.pictureBox1)).EndInit();

            this.ResumeLayout(false);

            this.PerformLayout();



        }



        #endregion



        private System.Windows.Forms.PictureBox pictureBox1;

        private System.Windows.Forms.Panel panel1;

        private System.Windows.Forms.Label label1;

        private System.Windows.Forms.Label label2;

    }

}




Form1.cs
using System.Drawing;
using System.Windows.Forms;
using Bytescout.BarCode;

// This application demonstrates two ways how you can show the barcode on a form: 
// 1. using PictureBox control;
// 2. painting it on a Panel control.
namespace DisplayBarcodeOnForm
{
    public partial class Form1 : Form
    {
        private Barcode _barcode = null;

        public Form1()
        {
            InitializeComponent();

            // Create Barcode Generator instance
            _barcode = new Barcode();
            _barcode.RegistrationName = "demo";
            _barcode.RegistrationKey = "demo";

            // Setup barcode
            _barcode.Symbology = SymbologyType.QRCode;
            _barcode.Value = "Testing Testing Testing Testing Testing Testing Testing Testing Testing Testing Testing Testing Testing";

            // Put the barcode image to PictureBox
            pictureBox1.Image = _barcode.GetImage();
        }

        // Paint the barcode image on a Panel control
        private void panel1_Paint(object sender, PaintEventArgs e)
        {
            Image barcodeImage = _barcode.GetImage();
            
            e.Graphics.DrawImage(barcodeImage, 0, 0);
        }
    }
}

Program.cs
using System;
using System.Collections.Generic;
using System.Windows.Forms;

namespace DisplayBarcodeOnForm
{
    static class Program
    {
        /// <summary>
        /// The main entry point for the application.
        /// </summary>
        [STAThread]
        static void Main()
        {
            Application.EnableVisualStyles();
            Application.SetCompatibleTextRenderingDefault(false);
            Application.Run(new Form1());
        }
    }
}

Resources.Designer.cs
��//------------------------------------------------------------------------------

// <auto-generated>

//     This code was generated by a tool.

//     Runtime Version:2.0.50727.8000

//

//     Changes to this file may cause incorrect behavior and will be lost if

//     the code is regenerated.

// </auto-generated>

//------------------------------------------------------------------------------



namespace DisplayBarcodeOnForm.Properties

{





    /// <summary>

    ///   A strongly-typed resource class, for looking up localized strings, etc.

    /// </summary>

    // This class was auto-generated by the StronglyTypedResourceBuilder

    // class via a tool like ResGen or Visual Studio.

    // To add or remove a member, edit your .ResX file then rerun ResGen

    // with the /str option, or rebuild your VS project.

    [global::System.CodeDom.Compiler.GeneratedCodeAttribute("System.Resources.Tools.StronglyTypedResourceBuilder", "2.0.0.0")]

    [global::System.Diagnostics.DebuggerNonUserCodeAttribute()]

    [global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()]

    internal class Resources

    {



        private static global::System.Resources.ResourceManager resourceMan;



        private static global::System.Globalization.CultureInfo resourceCulture;



        [global::System.Diagnostics.CodeAnalysis.SuppressMessageAttribute("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode")]

        internal Resources()

        {

        }



        /// <summary>

        ///   Returns the cached ResourceManager instance used by this class.

        /// </summary>

        [global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)]

        internal static global::System.Resources.ResourceManager ResourceManager

        {

            get

            {

                if ((resourceMan == null))

                {

                    global::System.Resources.ResourceManager temp = new global::System.Resources.ResourceManager("DisplayBarcodeOnForm.Properties.Resources", typeof(Resources).Assembly);

                    resourceMan = temp;

                }

                return resourceMan;

            }

        }



        /// <summary>

        ///   Overrides the current thread's CurrentUICulture property for all

        ///   resource lookups using this strongly typed resource class.

        /// </summary>

        [global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)]

        internal static global::System.Globalization.CultureInfo Culture

        {

            get

            {

                return resourceCulture;

            }

            set

            {

                resourceCulture = value;

            }

        }

    }

}


Settings.Designer.cs
��//------------------------------------------------------------------------------

// <auto-generated>

//     This code was generated by a tool.

//     Runtime Version:2.0.50727.8000

//

//     Changes to this file may cause incorrect behavior and will be lost if

//     the code is regenerated.

// </auto-generated>

//------------------------------------------------------------------------------



namespace DisplayBarcodeOnForm.Properties

{





    [global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()]

    [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.VisualStudio.Editors.SettingsDesigner.SettingsSingleFileGenerator", "8.0.0.0")]

    internal sealed partial class Settings : global::System.Configuration.ApplicationSettingsBase

    {



        private static Settings defaultInstance = ((Settings)(global::System.Configuration.ApplicationSettingsBase.Synchronized(new Settings())));



        public static Settings Default

        {

            get

            {

                return defaultInstance;

            }

        }

    }

}


Download Source Code (.zip)

Return to the previous page Explore BarCode SDK