Currently, I have a UI where the user chooses a product from a list. When they double click on the product of their choice another form shows the product with some additional information as well as the associated bar code. On this second form there is a print button. (This is where my question is) When the print button is clicked I want send this information to a Label Template and viewable (probably though a PrintPage) and then be able to be sent to a printer from that.
What is the best way to accomplish this? I can think of two different ways to accomplish this but I’m sure there are better ways out there.
1) I can create the template in XAML and then databind to the form
2) I can create the template in the form.vb ‘s _PrintPage event. (most straightforward but not the fastest)
- Is there an easier way to create the template and send the information to it and then print the template?
- It would be easier to just make another windows forms and design the template that way, but is it possible to send this form to a print object at runtime?
If I understand you correctly you want to control the process within your own program without using report tools? In that case I will list some thoughts about one implementation –
You can make a simple template functionality using (a serializable) dictionary that contains regions and region types. As you work with an absolute area (the label itself) you can for example do this:
Then in you code you convert the x,y,w,h into pixels based on the DPI and return a
Rectanglefor example. You can XML Serialize the dictionary to create other templates and so forth.The
Contentfield is initialized when parsed.To add you could do for example:
Then “render” the template into your canvas for printing:
Hope this gave some input.