|
web
newsgroups
|
|||||||||||||||||||||||
|
|||||||||||||||||||||||
Re: Printing ExampleHi,
There is a great tutorial you may find useful here; http://visualbasic.about.com/od/usingvbnet/a/printvb2005.htm Show quoteHide quote On 5 Dec, 07:49, "Pitaridis Aristotelis" <pitari***@hotmail.com> wrote: > Is there a complete example of how to print, print preview, change print > settings, etc. in VB.NET. > > Aristotelis Actually, I don't think it is very helpful as it doesn't really explain the
mechanisms going on. I have had a lot of printing problems because the VB Help file is unhelpful and I have found nowhere on the net that properly explains printing, and if it tries to, it makes too many assumptions. Effectively what happens is this. You need to create a PrintDocument Dim Withevents MyDoc as Drawing.Printing.PrintDocument the withevents automatically will create the PrintPage event. This event has a PrintPageEventArgs argument which is used to print to, and you use it by using its .Graphics property to print to, just as you would when painting a control (using GDI). Once you finish painting your page, you then use the args.HasMorePages which can be set False if no more printing or True if you have more to print. If True, the PrintPage event is raised again and you continue painting the next by now cleared page. You loop through this event until you have no more page painting to do and then you set the args.HasMorePages = False, otherwise you will simply print a blank page. Once you have finished painting, you can use the MyDoc.Print() to print it, or if you wish to show it in a PrintPreview by using its .Document=myDoc The PrintDocument uses you default page settings which you get to and change by using the MyDoc.DefaultPageSettings You will need to access these properties as it will then tell you your margins etc. Remember that when painting the document, you may use args.Graphics.DrawString() and you will need to set the x and y locations. However I have a problem in that I can't find a way of replacing the previously loaded document in the print preview with a new. I hope this helps. |
|||||||||||||||||||||||