Creating a barcode Picture within a program

Active Barcode Component produces its barcode image as a Windows metafile. This metafile is displayed directly in the area you create for the component - unless you set the Axbarcode.Visible property to FALSE.

To create a printable Picture object containing the barcode within a program the following steps are required:

1. Set those properties that Active Barcode Component requires to generate the barcode, the minimum of which are

 

Axbarcode1.CodeType         - specifies the barcode type required

Axbarcode1.Caption  - specifies the characters which make up
   the code

2. Allow the component's image to be displayed on the form (if required).

OR

Copy the components Picture property to an image on the form, eg.

If Axbarcode1.ErrorCode = 0 Then
    Image1.Picture = Axbarcode1.Picture

 

3. Printing the Barcode on the Printer

To print the barcode image on the printer use the PaintPicture method of the Printer object, eg.

Printer.ScaleMode = 6  ' sets printer scale to mm

Printer.PaintPicture Axbarcode1.Picture, 20, 20, Axbarcode1.PictureWidth,       Axbarcode1.PictureHeight

Printer.NewPage

Printer.EndDoc

 

4. Printing from VB.NET or C#

Printing from Managed code is accomplished using the PrintDocument control from the Visual Studio.NET ToolBox. Add the control to your application, then use it as illustrated below; in this example only the barcode image is printed.

 

    Private Sub print1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles print1.Click
        Try
            AddHandler PrintDocument1.PrintPage, AddressOf Me.PrintDocument1_PrintPage
            PrintDocument1.Print()
        Catch ex As Exception
            MessageBox.Show("An error occurred while printing", _
                ex.ToString())
        End Try
    End Sub

    Private Sub PrintDocument1_PrintPage(ByVal sender As System.Object, ByVal e As System.Drawing.Printing.PrintPageEventArgs) Handles PrintDocument1.PrintPage
        Dim newImage As Image = Axbarcode1.Picture
        Dim x As Integer
        Dim y As Integer
        x = Axbarcode1.PictureWidth ' in mm
        y = Axbarcode1.PictureHeight ' in mm
 
        Dim ulCorner As New Point(50, 50) ‘ set position on page
        Dim urCorner As New Point(x + 50, 50)
        Dim llCorner As New Point(50, 50 + y)
        Dim destPara As Point() = {ulCorner, urCorner, llCorner}
        e.Graphics.PageUnit = GraphicsUnit.Millimeter
        e.Graphics.DrawImage(newImage, destPara)
        ' Indicate that this is the last page to print.
        e.HasMorePages = False
    End Sub

 

More:

Using Active Barcode Components in Delphi