Neodynamic Barcode Professional 6.0 for Windows Forms (WinControl)
Microsoft .NET Framework (any version)
Microsoft Visual Studio .NET (any version)
As you probably already know, most printing jobs within .NET Framework are performed by using the PrintDocument class under System.Drawing.Printing namespace. The PrintDocument class is used to set the properties that describe what and where to print content such us strings, images and so on.
The main method the PrintDocument class features is Print which starts the document's printing process. After Print method is invoked, the PrintDocument raises a PrintPage event for each page to be printed. Here is where you should add your printing logic to an event handler for that event.
If your application needs to feature barcoding capabilities, it's also probably that printing documents containing barcode images are required as well.
Barcode Professional control features an overloaded method called DrawOnCanvas which lets you to draw the barcode image on any GDI+ Graphics object - an instance of System.Drawing.Graphics class. The PrintDocument's PrintPage event exposes a Graphics object where to paint the page content and here is where that Graphics object must be passed to the DrawOnCanvas method in order to get the barcode image printed.
This guide describes common scenarios regarding barcode printing using the PrintDocument class and Barcode Professional's DrawOnCanvas method:
This is the simplest barcode printing scenario. Here, the Graphics object exposed by PrintDocument's PrintPage event must be passed to the Barcode Professional's DrawOnCanvas method in order to get the barcode printed at the specified point (x, y).
Example
Supposing you have already set an event handler for the PrintDocument's PrintPage event, the following code inside that handler procedure will create a Barcode Professional object and will print the generated barcode at the specified point (in this case x=1in, y=1in) in the document/page.
Private Sub printDocumentObject_PrintPage(sender As Object, e As System.Drawing.Printing.PrintPageEventArgs)
'Create a Barcode Professional object
Dim bcp As New BarcodeProfessional()
'Barcode settings
bcp.Symbology = Symbology.Code39
bcp.Code = "123456789"
'...
'Print the barcode at x=1in, y=1in using DrawOnCanvas method
bcp.DrawOnCanvas(e.Graphics, New PointF(1F, 1F))
End Sub
private void printDocumentObject_PrintPage(object sender, System.Drawing.Printing.PrintPageEventArgs e)
{
//Create a Barcode Professional object
BarcodeProfessional bcp = new BarcodeProfessional();
//Barcode settings
bcp.Symbology = Symbology.Code39;
bcp.Code = "123456789";
//...
//Print the barcode at x=1in, y=1in using DrawOnCanvas method
bcp.DrawOnCanvas(e.Graphics, new PointF(1f, 1f));
}
One version of DrawOnCanvas method lets you to print a scaled barcode image by specifying the scale parameter. For instance, if you want to scale the original barcode to 50%, then the scale parameter must be specified as 0.5; if you want to scale the original barcode to 200%, then the scale parameter must be specified as 2; and so on.
As the previous scenario, the Graphics object exposed by PrintDocument's PrintPage event must be passed to the Barcode Professional's DrawOnCanvas method in order to get the barcode printed at the specified point (x, y) and scaled at the specified value.
Example
Supposing you have already set an event handler for the PrintDocument's PrintPage event, the following code inside that handler procedure will create a Barcode Professional object and will print the generated barcode scaled at 50% at the specified point (in this case x=2in, y=3in) in the document/page.
Private Sub printDocumentObject_PrintPage(sender As Object, e As System.Drawing.Printing.PrintPageEventArgs)
'Create a Barcode Professional object
Dim bcp As New BarcodeProfessional()
'Barcode settings
bcp.Symbology = Symbology.Code39
bcp.Code = "123456789"
'...
'Print the barcode at x=2in, y=3in and scaled down at 50% using DrawOnCanvas method
bcp.DrawOnCanvas(e.Graphics, New PointF(2F, 3F), 0.5F)
End Sub
private void printDocumentObject_PrintPage(object sender, System.Drawing.Printing.PrintPageEventArgs e)
{
//Create a Barcode Professional object
BarcodeProfessional bcp = new BarcodeProfessional();
//Barcode settings
bcp.Symbology = Symbology.Code39;
bcp.Code = "123456789";
//...
//Print the barcode at x=2in, y=3in and scaled down at 50% using DrawOnCanvas method
bcp.DrawOnCanvas(e.Graphics, new PointF(2f, 3f), 0.5f);
}
It's very common to need to print the barcode in order it fits a given area, for instance: The barcode must be printed on an area of size 1.5 inch x 1 inch.
One version of DrawOnCanvas method lets you to accomplish that by specifying the target area through barsAreaInInches parameter. Keep in mind the following points about the target area:
Again, as in the previous scenarios, the Graphics object exposed by PrintDocument's PrintPage event must be passed to the Barcode Professional's DrawOnCanvas method in order to get the barcode printed fitting the specified area.
Example
Supposing you have already set an event handler for the PrintDocument's PrintPage event, the following code inside that handler procedure will create a Barcode Professional object and will print the generated barcode in order it fits an area of size 2 inch x 1 inch.
Private Sub printDocumentObject_PrintPage(sender As Object, e As System.Drawing.Printing.PrintPageEventArgs)
'Create a Barcode Professional object
Dim bcp As New BarcodeProfessional()
'Barcode settings
bcp.Symbology = Symbology.Code39
bcp.Code = "123456789"
'...
'Print the barcode to fit an area of size 2x1in using DrawOnCanvas method
bcp.DrawOnCanvas(e.Graphics, New PointF(0,0), New SizeF(2F,1F))
End Sub
private void printDocumentObject_PrintPage(object sender, System.Drawing.Printing.PrintPageEventArgs e)
{
//Create a Barcode Professional object
BarcodeProfessional bcp = new BarcodeProfessional();
//Barcode settings
bcp.Symbology = Symbology.Code39;
bcp.Code = "123456789";
//...
//Print the barcode to fit an area of size 2x1in using DrawOnCanvas method
bcp.DrawOnCanvas(e.Graphics, New PointF(0,0), New SizeF(2f,1f));
}
We provide best-in-class customer service and support directly from members of our dev team! If we are available when you contact us, you will get a response in few minutes; otherwise the maximum turnaround is 24hs in most cases.