|
-
Mar 14th, 2006, 04:35 PM
#1
[RESOLVED] Print Picturebox (Not picture.. controls)
how do u print a picturebox ... like printform but just the picbox?
it is jus being used as a container.. there is no picture in it...
thanks!
JPnyc rocks!! (Just ask him!)
If u have your answer please go to the thread tools and click "Mark Thread Resolved"
-
Mar 14th, 2006, 06:08 PM
#2
Re: Print Picturebox (Not picture.. controls)
You can do it using BitBlt,another picturebox (invisible), and the PaintPicture method of the Printer object.
Picture1 = Your picturebox
Picture2 = An invisible picturebox
VB Code:
Private Declare Function BitBlt Lib "gdi32" _
(ByVal hDCDest As Long, ByVal XDest As Long, ByVal YDest As Long, _
ByVal nWidth As Long, ByVal nHeight As Long, ByVal hDCSrc As Long, _
ByVal xSrc As Long, ByVal ySrc As Long, ByVal dwRop As Long) As Long
Private Sub Command1_Click()
Picture2.Width = Picture1.Width
Picture2.Height = Picture1.Height
BitBlt Picture2.hDC, 0, 0, Picture1.ScaleWidth, Picture1.ScaleWidth, Picture1.hDC, 0, 0, vbSrcCopy
Picture2.Picture = Picture2.Image 'Persist the image into the picture
SavePicture Picture2.Picture, "C:\MyPic.jpg" 'If you want to save it
Printer.PaintPicture Picture2.Picture, 0, 0 'print at x=0 and y=0
Printer.EndDoc
End Sub
Private Sub Form_Load()
Picture1.AutoRedraw = False
Picture1.ScaleMode = vbPixels
Picture2.AutoRedraw = True
Picture2.ScaleMode = vbPixels
Picture2.AutoSize = True
Picture2.Visible = False
End Sub
Last edited by jcis; Mar 16th, 2006 at 10:36 AM.
-
Mar 15th, 2006, 10:44 AM
#3
Re: Print Picturebox (Not picture.. controls)
absolutely perfect!! thanks!
JPnyc rocks!! (Just ask him!)
If u have your answer please go to the thread tools and click "Mark Thread Resolved"
-
Jul 14th, 2006, 11:43 PM
#4
Addicted Member
Re: [RESOLVED] Print Picturebox (Not picture.. controls)
I have tried your code and seems work fine (I can capture the controls inside the picture box)
Except I got a strange problem, the picture2 only has a small porttion of upper left corner of picture 1!
I dont know whats wrong (I have debug and see that the scaleheight/width is 768/1024), but when I make picture2 visible, it only has a small portion shown
Any assitance will be much appreciated
-
Jul 15th, 2006, 12:55 AM
#5
Addicted Member
Re: [RESOLVED] Print Picturebox (Not picture.. controls)
I have fixed it, but dont know why
The reason may be my Picture1 is inside another picturebox
I changed to use the outside picturebox size for the BitBlt
thanks for your code
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|