Help with printing

Hi,
I'm making a program in vb.net, one of the features of this program is printing out an invoice. How would i go about doing this The information I want to print contains an image, 3 textboxes and 2 listboxes. Is there a way to just print this without a button etc in the interface I tried a "on load" command but it printed before the form had loaded (using the capture screen method). My friend tells me that there is a way of doing it where you put all the items you want to print into a 'panel' and only the panel gets printed however, he doesn't know how to do this and I have been unsucessful in locating this feature.

Any help will be most appreciated,
Thanks a lot,
Liam


Answer this question

Help with printing

  • cykophysh

    Do a search on printing, you may find some help.

    But I'd have to question what exectly is going on - you are printing what you need after the form has loaded (I really don't think this is what you mean, or what I understand) Why do you need a form how does the data get into these controls Regardless, printing the rendered controls is going to look terrible and unprofessional.

    Lookup the printing Namespace in help. What you would want to do is learn a bit, also, about 'graphics' objects: layout your invoice text on a piece of paper, measure the locations, and create that in code (there are text rendering commands to place text at specific locations). The PrintDocument object help has a simple sample of this.



  • Viswanath

    SJ is correct, and I'd also say to follow his suggestions.  Learning the PrintDocument and related controls will not only give you freedom to print how, when, and where you want, it will also help you better understand how printing works in general.

    But I'll also throw this out there:

    Before VS05 made printing so much easier, I had two "kludge" methods that I used all the time when I wanted to render a document for print:  MS Word automation and dynamic HTML generation.

    If I new for certain that Word would be installed anywhere my app would run than I would usually create an instance of Word, inject my text, apply formatting, and either show Word for the user to do as they wish, or just print the document.  This solution was more robust in that I could use pre-defined Word templates, packaged with my app, that provided a lot of flexability and power in formatting and goodies (all the cool stuff Word can do).  But, this option can be a little more time consuming until you get good at it (or generate assembiles to reuse that make it fast!).

    The other option was to simply create a text file with an HTM extension and inject my text into it using HTML Tags for formatting.  Then launch the iexplore process with the filename as a parameter.  This would open IE, with my HTML report document loaded and the user could just hit print in IE.  This is a pretty quick and easy ("fast and dirty" as a friend used to say) way to spit out some data in a fairly nice format.

    One side benefit to either method, but particularly the latter, is that not only do these doucment print well, they are also ready to email, or e-fax - giving you a little more flexibility in distribution options.



  • Help with printing