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 SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How do I print large picturebox to printer object using PaintPicture?

Status
Not open for further replies.

goldi

Programmer
Mar 21, 2001
31
0
0
US
I have a report that I put to a picture box for viewing. It can be larger than the printer object. When it is larger (let's say it's about twice the width and twice the height of the printer object), I want to split it into 4 chunks to print. I can get the top / left quad to print, but I can't seem to get any others to print.

I find the description of the PaintPicture to be very confusing.
 

i think something close to this will work

Printer.PaintPicture Picture1.Picture, 0, 0, , , 0, 0, CLng(Picture1.Width / 2), CLng(Picture1.Height / 2)
Printer.PaintPicture Picture1.Picture, 0, 0, , , CLng(Picture1.Width / 2) + 1, , , CLng(Picture1.Height / 2)
Printer.PaintPicture Picture1.Picture, 0, 0, , , , CLng(Picture1.Height / 2) + 1, CLng(Picture1.Width / 2), CLng(Picture1.Height / 2)
Printer.PaintPicture Picture1.Picture, 0, 0, , , CLng(Picture1.Width / 2) + 1, CLng(Picture1.Height / 2) + 1, CLng(Picture1.Width / 2), CLng(Picture1.Height / 2)
 
In the PaintPicture method, you can specify a region within the source picture that you want to "clip".

Printer.PaintPicture Picturebox1.Picture,X1,Y1,Width1,Height1,X2,Y2,Width2,Height2

This is the general format for the command.

X1 and Y1 tell where on the printer to place the top left of the picture. ( Most likely these will both be 0 )

The Width1 and Height1 values determine what size the image is going to be on your printer.

The X2 and Y2 values determine the top left corner of the clipping region inside the picturebox.

The Width2 and Height2 values set the size of the clipping region in the picturebox.

The hard part is making sure that you keep your aspect ratios the same between the printer and the picturebox, so that you don't inadvertantly "stretch" the picture that goes to the printer. If the Width1 and Height1 values are the same as the Width2 and Height2 values, then you are OK. . ( make sure you have your scalemodes set the same for both the printer and the picturebox, or you will need to do some conversion math )


Robert
 
I can't figure out what I am doing wrong!! If I put a simple command like this:

Printer.PaintPicture picReport.Picture, 0, 0, , , 0, 0

I get the top, left of my report (like I want), but if I add any width or height after the x2,y2 it prints the bottom of my report (and it's wrong)! I have tried setting both picture and printer to scale mode of twips and to centemeters and it doesn't seem to matter. Also, if I set my x2,y2 to anything besides 0 I get an error on the printer.
 
also, if I put in the command like this:

Printer.PaintPicture picReport.Picture, 0, 0, , , 0, 27.14

(This command tells me that I want x2=0 and y2=27.14 cm, so the top left corner of my clipping region is all the way to the left and 27.14 cm down - right!)

That command gives me the top left corner of my report and not even the entire top left - only the first 9.5 cm of it!!

HELP!!!!
 
Is the entire report visible inside the picturebox when you issue your print command?

Robert
 
It is a scrolling picturebox. Only part of the report is visible at a time (until either scroll down or over), but the entire report is contained within this picturebox.

 
OK, because you are leaving the values for Width1 and Height1 blank, it is using the size of the picturebox as the destination size ( this is the default ).

I'm not sure if the Width2 and Height2 values specify the visible area inside the picturebox, or if they refer to the picture itself ( even if it extends outside the visible box ).

What you might try, is just before doing the paintpicture, is to resize the picturebox to a size that would show the entire report, and then change it back after the paintpicture.

Robert
 
OK I FIGURED IT OUT!!!!!

The confusion lies in the clipping region. The x1,y1, width1 and height1 work just the way I understood.

BUT - x2,y2 are not the left/top coordinates - they are the left/bottom coordinates and you measure bottom to top for the height2 and measure left to right for the width2.

 
UPDATE!

I feel somewhat like an idiot, but here goes....

The command only works BACKWARDS when you are printing to an HP 4000TN printer. When I took my program to another office and tried printing it on an HP 4050TN it did not work correctly.

I then changed all my calculations to how I thought it should work (and how the two wonderful people who responded to my question said it should be), it worked like a charm.

Be careful with HP 4000TN printers. Maybe the PCL version or the firmware version that we have is the bad thing, but I have had other strange things happen with that printer. Things just don't work the same on that printer. I had posted another question about KILLDOC and found out that it was that printer that didn't work with KILLDOC.

Sorry, to whoever looks at this problem, for the confusion.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top