Create and display barcode on a form in Visual C# .NET with Bytescout BarCode SDK for .NET - ByteScout

Create and display barcode on a form in Visual C# .NET with Bytescout BarCode SDK for .NET

  • Home
  • /
  • Articles
  • /
  • Create and display barcode on a form in Visual C# .NET with Bytescout BarCode SDK for .NET

The following sample demonstrates how to use Barcode image control in Visual C# (C sharp)

WinForms applications:

When using Bytescout.BarCodeControl in a Windows application, you just need to copy the Bytescout.BarCode.dll file to your application’s directory and add a reference to Bytescout.BarCode component in your project references.

The following example illustrates how you can set properties of BarcodeControl control with C# BarCode Generator. This example requires that BarcodeControl with barcodeControl1 name is added to a form and that the Bytescout.BarCode namespace has been added to the source code for your form. You can also fine tune control appearance by means of Windows Forms designer.

private void SetMarginsAndRotate()
{
// create new Margins object and set it’s properties
Bytescout.BarCode.Margins margins1 = new Bytescout.BarCode.Margins();
margins1.Bottom = 0;
margins1.Left = 50;
margins1.Right = 50;
margins1.Top = 0;
this.barcodeControl1.Margins = margins1;

// set rotation angle (270 degrees clockwise)
this.barcodeControl1.Angle = Bytescout.BarCode.RotationAngle.Degrees270;
}

Non-visual class

You can also use non-visual class to generate barcode and save generated barcode into PNG, JPG or another image file:

using System;
using System.Collections.Generic;
using System.Text;
using System.Diagnostics;

using Bytescout.BarCode;

namespace Sample
{
class Program
{
static void Main(string[] args)
{
// Create new barcode
Barcode barcode = new Barcode();

// Set symbology
barcode.Symbology = SymbologyType.Code39;
// Set value
barcode.Value = “Sample”;

// Save barcode to image
barcode.SaveImage(“result.png”);

// Show image in default image viewer
Process.Start(“result.png”);
}
}
}

Tutorials:

prev
next