Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations wOOdy-Soft on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How to print one form "X" times per page 1

Status
Not open for further replies.

phpPete

Programmer
Feb 25, 2002
88
US
I'd like to print the same form 3 times per page, like chekcs on a page...in this case it's for gift certificates.



For example: frmSample.PrintForm prints once per page.

Can anyone point me in the right direction?

Thanks,

PAS
 
First, place this code in a public module:

Global Const WM_PAINT = &HF

Global Const WM_PRINT = &H317

Global Const PRF_CLIENT = &H4& Global Const PRF_CHILDREN = &H10&

Global Const PRF_OWNED = &H20&

Declare Function SendMessage Lib "user32" Alias "SendMessageA" (ByVal hwnd As Long, ByVal wMsg As Long, ByVal wParam As Long, ByVal lParam As Long) As Long


Place a picturebox somewhere on your form. Name it "FormPicture". Set its Visible property to False, AutoRedraw to True, and BorderStyle to None.

Then, in the module that is to do the printing, put this code:

Dim rv As Long

FormPicture.Width = Me.Width
FormPicture.Height = Me.Height
FormPicture.BackColor = Me.BackColor

Me.SetFocus
rv = SendMessage(Me.hwnd, WM_PAINT, FormPicture.hDC, 0)

rv = SendMessage(Me.hwnd, WM_PRINT, FormPicture.hDC, PRF_CHILDREN + PRF_CLIENT + PRF_OWNED)

FormPicture.Picture = FormPicture.Image
FormPicture.Refresh

Printer.PaintPicture FormPicture.Picture, 0, 0

Printer.EndDoc


OK, this prints your form and ( most of ) it's controls to the page.

This is essentially what "PrintForm" does, but this allows you to specify *where* on the page your form will be printed, and how many times you want to print it on the page ( before issuing the Printer.EndDoc command )

By modifying the line:

Printer.PaintPicture FormPicture.Picture, 0, 0

We specify the place on the page the form will be printed. the last two numbers in that line are Single values that specify the X and Y position on the printer page, for the Top / Left corner of your form. ( look up PaintPicture on MSDN for more on what this command can do )

By looping through the print commands 3 times, changing the position of your form to print out each time, then giving the Printer.EndDoc command, you get the required 3 times per page.

Note: Some controls will not print their contents with this code as is. Most of the standard ones will, but the Picturebox will not. If you have any Pictureboxes on your form, Set your forms AutoRedraw to True, and transfer their images to the form like this: ( This also applies to FlexGrids. )

Me.PaintPicture Picture1.Picture, Picture1.Left, Picture1.Top

And then make the picturebox invisible before you print the form:

Picture1.Visible = False

After printing the form, reset it's picture value to nothing:

Set Me.Picture = Nothing

And make your picturebox visible again.

Hope this helps to get you on track.

Robert
 
Vampire!!! You da man!!!

Many thanks for your response.

That's the ticket!

PAS
 
A FOR loop of what? PrintForm methods? Won't work, because after every PrintForm, you automatically get a new sheet of paper.

Robert
 

THOMASNG: You need to start reading the questions a little slower...and a little more careful, and see the responses already made. You are throwing too much confusion into the subjects.

This question was pretty clear:

"I'd like to print the same form 3 times per page,..."

That means:

"I'd like to print the same form 3 times per page" [/i][/u]*******************************************************
General remarks:
If this post contains any suggestions for the use or distribution of code, components or files of any sort, it is still your responsibility to assure that you have the proper license and distribution rights to do so!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top