1月28日
I have to say, I had fun coding this feature. I wanted to print some 3of9 bar code labels for employee badges in a WinForms app I am rolling out. I was thinking this was going to involve some custom api and buying some font package (some are big $$). It turned out this was surprisingly simple and a fun report to build. Here is a sample label (extra points for first person to discover what is the barcode:
What you need:
- SqlServer or some other data source. I am using Linq and Entity Framework. You could you XML, csv or memory objects as you need.
- Visual Studio and the MicrosoftReportViewer control. Not sure if this is included in Express addition or not. Let me know.
- A Dymo LabelWriter 400 or other such printer that can print single labels in a stream. I really like the Dymo for its ease of use, simple loading, and it is well made. Also it is a thermal printer, so you don't need to change any ribbons - ever. About $100. Order the label sizes you need - remember you need to order their special labels as they are thermal. I am using 3.5" x 1". I also like this, because you don't waste a lot of labels like trying to print 8.5"x11" sheets. You always end up with half a sheet you don't know what to do with. So get a Dymo, you can use it for other things too.
- A 3of9 TrueType font. I use the Free3of9 ttfs here: http://www.squaregear.net/fonts/free3of9.shtml. Hats off to Matthew Welch for his nice font package he is sharing!
Just download and install the two fonts from the Control panel.
Steps to create the label report. I am using 3.5" x 1" labels, but same steps apply for other sizes:
- Install the Free3of9 fonts and logout and back in to get the fonts loaded.
- Create a VS WinForms project. You could do the same with WPF, but I used WinForms.
- Add a new Form to hold your report control.
- Add a MicrosoftReportViewer control to the form. I have to give props to MS for this control. It is a great control that puts a lot of power in your hands.
- Create a new report from the drop down on the top right of the control.
- Once your in the designer, change the report properties Layout to 3.4in wide and .9in high. I set it just a tad smaller then the label so as not to get strange page breaks. Set all four margins to 0.
- Change the Body of the report surface to 3.4 x .9in or smaller. Just don't make it larger then the page layout or you will get page breaks
- Now your surface is your "label". Add your Table and other controls as needed for your label within this surface.
- Change the font family to 3of9 Extended for the field that you want to show as a barcode.
- Add as many Detail rows to your table as you need vertically. I used 2 rows to show Employee name on top and EmployeeID as Barcode under it.
- Select the last row and right-click "Edit Group..." and group on some unique field such as employee id. Also Check "Page break at end." so that your page will break to a new label after each employee.
- In the load event of the form, get your data as a list and set the DataSource property of the report control to the list and RefreshReport() after that.
- Run your report and adjust things as needed. Fast, clean and professional barcodes in a snap right from your next windows application.
Misc:
- Set the Dymo Advanced properties on the printer driver to "Barcodes and images" to get really clean quality. Set the Color to black and white, not sure why they have a Color option, but you can play with output as needed.
- Can also use this same method to make a production receipt printer application with the Dymo with full graphics abilities. Just get the Receipt paper they offer and change the report size.
- Not sure how to make it print directly to a printer without user intervention yet. Say you wanted a receipt to print after clicking a button and not show the print dialog. If anyone knows how to make ReportViewer do this, please let me know.
- Have fun with your new 3of9 labels! I will try to add some pictures here and a sample project soon.
- When I get my USB barcode scanner with Serial simulation driver, I hope to post back with some code showing how to use the Serial class so we can scan our new labels.
--William