0

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.

John Saunders
  • 160,644
  • 26
  • 247
  • 397
  • The most complex part tends to be the layouting, where to put different objects on the page/screen. If you want an image to fill half the page and text flow on the side or similar. But it depends on your needs. You might try to tell how complex layout you need to help get a suitable answer. – Albin Sunnanbo Feb 14 '11 at 20:48
  • I'm just looking for where to start at this point. Most info I find seems to be either focused on painting to a Form OR painting to Printer. I've built webpages, and yes the layout is tedious. I'm looking for something that has addressed the Form and the Printer in one example so that I don't have to overcome all of the errors associated with the Noobie experience. :) –  Feb 14 '11 at 21:08
  • Looks like you solved your problem a long time ago but I would suggest anyone else needing to do this should try out ObjectListView. (http://objectlistview.sourceforge.net/) It's a great little grid and it has a print mode that turns the grid into a report. You can do custom drawing if you want, in both the live grid and the printed report. If you mostly just want to print a grid of data then you should give it a try. It uses an opensource license but you can pay to get a commercial license (I did). – Steve Hiner Oct 23 '14 at 23:03

2 Answers2

0

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...

Taco
  • 2,004
  • 1
  • 13
  • 6
  • I still have to create the report. It doesn't matter if it is PDF or real Paper, the data has to be formatted and told where to go. Neo might understand the 1s and 0s, but management at meetings will not. –  Feb 15 '11 at 20:20
  • I know. The second sentence was not the most important one. But what I tried to suggest was to have a look at defining a PDF report using a library like iText (or any other that can create a PDF) instead of using Graphics.DrawText etc directly. In that way you can see it on the screen, have it on the desks of your boss and you can send it by email. – Taco Feb 16 '11 at 00:01
  • ... or Microsoft XPS-documents (http://msdn.microsoft.com/en-us/magazine/cc163664.aspx) as an alternative for PDF-documents. – Taco Feb 16 '11 at 00:11
  • I have to use the Graphics object from the OnPaint event and write my text to positions on the screen to display it. The only way someone would be able to print that (if I did not code something) would be for them to use the Print Screen button. If I have to use the Pen and Brush objects to create my form to view on the screen, I should be able to do something similar to get the data on the screen to a printer. –  Feb 16 '11 at 15:12
0

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.