DBarcode Active DLL 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 DBarcode Active DLL requires to generate the barcode, the minimum of which are
AbcDl71.CodeType - specifies the barcode
type required
AbcDl71.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 AbcDl71.ErrorCode = 0 Then
Image1.Picture = AbcDl71.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 AbcDl71.Picture, 20, 20, AbcDl71.PictureWidth,
AbcDl71.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 =
AbcDl71.Picture
Dim x As
Integer
Dim y As
Integer
x = AbcDl71.PictureWidth '
in mm
y = AbcDl71.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: