PDA

Click to See Complete Forum and Search --> : Print Form Method


sgrya1
Dec 9th, 2006, 10:24 AM
Attached is a method to print a form if you want to :

Print controls as they appear on the form.
Print a form that is larger than the window size.
Scale the printed output to the papersize.

It's not pretty and a little cumbersome but I couldn't find any simpler way with what I wanted to display. If it's of use to anyone....

Method:

In the example there are 4 pictureboxes and an MHSFlexgrid. Picture1 is the main scrollable picture within the form. Picture 2 is an additional picture located within the scrollable form picture. Pictures 3 and 4 are needed to paint images of Pictures 1 and 2 onto. Send pictures 3 and 4 to back by right clicking them. The sizes of pictures 3 and 4 aren't important as they are resized to the sizes and locations of pictures 1 and 2 at runtime. At runtime the visibility, backcolor and border styles are changed so that no part of them accidently prints out.

First up, Picture1 gets painted to Picture 2 which then gets sent to the printer. Unfortunately Picture3 and the flexgrid don't get painted so I had to do them seperately.

Paint the Flexgrid to Picture 2.

For some reason Picture 3 can't be painted to Picture 2 so I had to paint it to picture 4 then send picture4 to the printer seperately.

The attached should explain the rest. Note that if frames are used then these also have to be painted to invisible pictureboxes and sent to the printer seperately similar to what is required for Picture 3.

Hope it saves someone some grief.

Edit: PrintDialog reference removed as mentioned in following post.

CVMichael
Dec 9th, 2006, 08:12 PM
I get an error at this line:
Dim printDlg As PrinterDlg
It does not know what PrinterDlg is... (and I don't know either...)

When I go to references, I see "MISSING: Microsoft VB Printer Dialog(PSS)"

So, of course, I did a little research, and I found it here:
http://support.microsoft.com/kb/322710

After I registered it, the program works fine...

Nicely done ! :thumb:

sgrya1
Feb 4th, 2007, 04:17 PM
Just to add, there are much simpler ways but they are restrictive.

Me.PrintForm for example only prints what is visible on screen.

These articles helped me nut my problem out.

http://support.microsoft.com/default.aspx?scid=kb;en-us;161299
and
http://support.microsoft.com/kb/230502/