Results 1 to 5 of 5

Thread: [RESOLVED] Print Picturebox (Not picture.. controls)

  1. #1

    Thread Starter
    PowerPoster Static's Avatar
    Join Date
    Oct 2000
    Location
    Rochester, NY
    Posts
    9,390

    Resolved [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"

  2. #2
    PowerPoster jcis's Avatar
    Join Date
    Jan 2003
    Location
    Argentina
    Posts
    4,430

    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:
    1. Private Declare Function BitBlt Lib "gdi32" _
    2.     (ByVal hDCDest As Long, ByVal XDest As Long, ByVal YDest As Long, _
    3.     ByVal nWidth As Long, ByVal nHeight As Long, ByVal hDCSrc As Long, _
    4.     ByVal xSrc As Long, ByVal ySrc As Long, ByVal dwRop As Long) As Long
    5.    
    6. Private Sub Command1_Click()
    7.     Picture2.Width = Picture1.Width
    8.     Picture2.Height = Picture1.Height
    9.     BitBlt Picture2.hDC, 0, 0, Picture1.ScaleWidth, Picture1.ScaleWidth, Picture1.hDC, 0, 0, vbSrcCopy
    10.     Picture2.Picture = Picture2.Image 'Persist the image into the picture
    11.        
    12.     SavePicture Picture2.Picture, "C:\MyPic.jpg"  'If you want to save it
    13.     Printer.PaintPicture Picture2.Picture, 0, 0 'print at x=0 and y=0
    14.     Printer.EndDoc
    15. End Sub
    16.  
    17. Private Sub Form_Load()
    18.     Picture1.AutoRedraw = False
    19.     Picture1.ScaleMode = vbPixels
    20.     Picture2.AutoRedraw = True
    21.     Picture2.ScaleMode = vbPixels
    22.     Picture2.AutoSize = True
    23.     Picture2.Visible = False
    24. End Sub
    Last edited by jcis; Mar 16th, 2006 at 10:36 AM.

  3. #3

    Thread Starter
    PowerPoster Static's Avatar
    Join Date
    Oct 2000
    Location
    Rochester, NY
    Posts
    9,390

    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"

  4. #4
    Addicted Member
    Join Date
    May 2002
    Location
    FlyingOffice
    Posts
    178

    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

  5. #5
    Addicted Member
    Join Date
    May 2002
    Location
    FlyingOffice
    Posts
    178

    Talking 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
  •  



Click Here to Expand Forum to Full Width