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!
Printable View
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!
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
absolutely perfect!! thanks!
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
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