Active 2D-Barcode Control produces its barcode image as a Windows metafile. This metafile is displayed directly in the area you create for the control - unless you set the A2barcode.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 which Active 2D-Barcode Control requires to generate the barcode, the minimum of which are
AdBarcode1.CodeType - specifies the barcode type required
AdBarcode1.Caption -
specifies the characters which make up
the code
2. Allow the control's image to be displayed on the form (if required).
OR
Copy the controls Picture property to an image on the form, eg.
If AdBarcode1.ErrorCode = 0 Then
Image1.Picture = AdBarcode1.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 AdBarcode1.Picture, 20, 20, AdBarcode1.PictureWidth, AdBarcode1.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 =
AxAdBarcode1.Picture
Dim x As
Integer
Dim y As
Integer
x = AxAdBarcode1.
PictureWidth ' in mm
y =
AxAdBarcode1. 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: