For my example, I have set the barcode font size to 15 point. You
are free to adjust is as needed for your application, but keep in
mind that a small barcode may not be readable by all scanners and
some wedge type scanners cannot read extremely wide barcodes. You
will need to determine the proper size for your application.
#region Methods
public void Print ()
{
PrintDocument tmpprndoc = new PrintDocument () ;
tmpprndoc.PrintPage +=
new PrintPageEventHandler (toPrinter);
// For debugging purposes, only print to the PrintPreview
#if DEBUG
PrintPreviewDialog tmpprdiag = new printpreviewdialog() ;
tmpprdiag.Document = tmpprndoc;
tmpprdiag.Show() ;
#else
tmpprndoc.Print () ;
#endif
}
-
private void toPrinter (Object sender, PrintPageEventArgs e)
}
Graphics g = e.Graphcs;
Brush br = new SolidBrush (Color.Black) ;
// the Asterisk (*) is used to delimit the barecode, and is required as
the start and stop charachters by the 3of9 Symbology.
g.DrawString("*" + m_BarcodeData + "*", m_BarcodeFont, br, 50, 50) ;
if (m_ShowHumanReadable)
{
g.DrawString (m_BarcodeData, m_PrintFont, br, 50, 65) ;
}
}
-
- #endregion
This code originally appeared in an image, which you can see here.
Please note that I have set the #if DEBUG directive so that the application
will only print to the PrintPreview Dialog during testing. Doing this
saves greatly in both time and printer costs.
The human readable element of the barcode here is optional.
Source Code - SimpleBarcoding.zip
About the Author: James Divine is currenlty involved in a large scale SAP re-
implementation for Wausau Homes (http://www.wausauhomes.com).
The company has chosen the .Net platform for building a UI for the
mobile sales force. .Net will be used to create a fully dynamic UI
that will be driven by the SAP's Variant using reflection and Xml.
The interface will be delivered with User Controls embedded in HTML
pages (allowing WinForms capability in IE).
Read this Newsletter at: http://www.cprogrammingtrends.com/2003/0923.html |
|