Using in VB.NET and C#

 

 

This example illustrates how to add barcodes to a VB.NET or C# application.

 

To add BarCodeWiz ActiveX Control to your toolbox, right-click on one of the sections (such as General) and click on Choose Items...

ChooseToolboxItems1

 

Switch to the COM Components tab, select BarcodeWiz Class, and click OK.

ChooseToolboxItems2

 

BarcodeWiz Class will now appear in the toolbox.

BarcodeWizClassShown

 

Insert a barcode and a button control onto the form by dragging from the Toolbox.

The barcode control is named AxBarCodeWiz1 by default.

Dialog1

 

The following code will print a barcode on the page in position 100,100 pixels from top/left.

 

VISUAL BASIC.NET Example

 

Public Class Form1

  Private Sub Button1_Click(ByVal sender As System.Object, _

                          ByVal e As System.EventArgs) Handles Button1.Click

      'Set the barcode properties.

      AxBarCodeWiz1.Symbology = BARCODEWIZLib.enumSYMBOLOGY.Code_128_Auto

      AxBarCodeWiz1.Barcode = "HELLO 123"

 

      Dim pd As New System.Drawing.Printing.PrintDocument

      AddHandler pd.PrintPage, AddressOf pd_PrintPage

 

      Dim pp As New PrintPreviewDialog

      pp.Document = pd

      pp.ShowDialog(Me)

  End Sub

 

  Private Sub pd_PrintPage(ByVal sender As Object, _

                          ByVal ev As System.Drawing.Printing.PrintPageEventArgs)

      'Add the barcode at position (100,100).

      ev.Graphics.DrawImage(AxBarCodeWiz1.Picture, 100, 100)

 

      'No more pages, let's print.

      ev.HasMorePages = False

  End Sub

End Class

 

 

C# Example

 

using System;

using System.Collections.Generic;

using System.ComponentModel;

using System.Data;

using System.Drawing;

using System.Text;

using System.Windows.Forms;

using System.Drawing.Printing;

 

namespace WindowsApplication1

{

  public partial class Form1 : Form

  {

      public Form1()

      {

          InitializeComponent();

      }

 

      private void button1_Click(object sender, EventArgs e)

      {

              // Set the barcode properties.

          axBarCodeWiz1.Barcode = "HELLO 123";

          axBarCodeWiz1.Symbology = BARCODEWIZLib.enumSYMBOLOGY.Code_128_Auto;

 

          PrintPreviewDialog pp = new PrintPreviewDialog();

          PrintDocument pd = new PrintDocument();

          pd.PrintPage += new PrintPageEventHandler(pd_PrintPage);

 

          pp.Document = pd;

          pp.ShowDialog(this);

      }

 

      private void pd_PrintPage(object sender, PrintPageEventArgs ev)

      {

              // Add the barcode at position (100,100).

          ev.Graphics.DrawImage(axBarCodeWiz1.Picture, 100, 100);

 

              // No more pages, let's print.

          ev.HasMorePages = false;

      }

  }

}