Painting to Form then to Printer

333 Views Asked by At

I often find myself needing to create custom reports that do NOT work with Crystal Reports or Report Viewer. Often, I hack a DataTable together and dumping that into a DataGridView control. It is never pretty, and printing is difficult.

What I need is a class that I can call using the OnPaint event, but I've never sat down and written all of the Pen and Brush commands until now.

Painting to the screen and painting to a printer both use the Graphics object, so I want to build a class that I'd pass in the Graphics object, my window bounds (a Rectangle), and some data (in the form of an instance of my class) that I'd use to paint a form or a sheet of paper.

That sounds like a great concept!

Surely, someone has done something like this before.

Does anyone know of a book, a website tutorial, or video that goes into this?

If someone wants to write all that out for me here, more power to you - but I'd think that would be too much work.

2

There are 2 best solutions below

0
On BEST ANSWER

I wound up going with a PrintPreview dialog box and writing everything in the OnPaint event.

Once that was done, I completely ditched the form. One PrintPreview that actually serves as the form for my Clients to view before going straight to the printer.

FYI: Positioning every item on the page was tedious.

4
On

How about generating a PDF document using iText (free open source PDF library - http://itextpdf.com/) instead of the graphics object? Then the user can have a digital report instead of a paper one, a little bit more environment friendly...