Results 1 to 14 of 14

Thread: Picture Box, please?

  1. #1

    Thread Starter
    Junior Member
    Join Date
    Jun 2006
    Posts
    18

    Picture Box, please?

    i use picture box as a container.
    for example: a picture box contains button, textbox.
    how do i save the content of picture box to an image (bmp, jpg, etc)?
    or how do i print the content of picture box?
    really thanx for ur help..

  2. #2
    Addicted Member Redangel's Avatar
    Join Date
    Oct 2005
    Location
    England
    Posts
    214

    Re: Picture Box, please?

    VB Code:
    1. Private Sub Command1_Click()
    2.     With CommonDialog1
    3.         .DialogTitle = "Save"
    4.         .Filter = Picture (*.bmp)|*.bmp
    5.         .ShowSave
    6.         SavePicture PictureBox1.Image, .FileName
    7.     End With
    8. End Sub
    Last edited by Redangel; Jun 9th, 2006 at 09:48 AM. Reason: Code Tags

  3. #3

    Thread Starter
    Junior Member
    Join Date
    Jun 2006
    Posts
    18

    Re: Picture Box, please?

    thanx for ur reply.
    i tried a picture box as a container of a button n then i save in bmp file.
    when i open the file, it only saves back color of the picture box...

  4. #4
    Hyperactive Member Dmitri K's Avatar
    Join Date
    Sep 2002
    Location
    West Palm Beach, FL
    Posts
    444

    Re: Picture Box, please?

    Try to see if this thread will be of any help

    http://www.vbforums.com/showthread.p...handle+picture

  5. #5
    PoorPoster iPrank's Avatar
    Join Date
    Oct 2005
    Location
    In a black hole
    Posts
    2,729

    Re: Picture Box, please?

    If you don't have any other 'child' picturebox or some fancy control, the following code may work:
    VB Code:
    1. ' Add another PictureBox (Picture2) in your form
    2. Option Explicit
    3.  
    4. Private Declare Function SendMessage Lib "user32" _
    5.     Alias "SendMessageA" ( _
    6.         ByVal hwnd As Long, _
    7.         ByVal wMsg As Long, _
    8.         ByVal wParam As Long, _
    9.         ByVal lParam As Long) As Long
    10.  
    11. Const WM_PAINT = &HF
    12. Const WM_PRINT = &H317
    13. Const PRF_CLIENT = &H4&    ' Draw the window's client area
    14. Const PRF_CHILDREN = &H10& ' Draw all visible child
    15. Const PRF_OWNED = &H20&    ' Draw all owned windows
    16.  
    17. Private Sub Command1_Click()
    18.   Picture2.Cls
    19.   SendMessage Picture1.hwnd, WM_PAINT, Picture2.hDC, 0
    20.   SendMessage Picture1.hwnd, WM_PRINT, Picture2.hDC, PRF_CHILDREN + PRF_CLIENT + PRF_OWNED
    21.   SavePicture Picture2.Image, "c:\Test.bmp"
    22. End Sub
    23.  
    24. Private Sub Form_Load()
    25.     Picture2.Visible = False
    26.     Picture2.AutoRedraw = True
    27.     Picture2.Width = Picture1.Width
    28.     Picture2.Height = Picture1.Height
    29. End Sub
    Usefull VBF Threads/Posts I Found . My flickr page .
    "I love being married. It's so great to find that one special person you want to annoy for the rest of your life." - Rita Rudner


  6. #6

    Thread Starter
    Junior Member
    Join Date
    Jun 2006
    Posts
    18

    Re: Picture Box, please?

    thanx to Redangel for told me about SavePicture function.
    thanx to Dmitri K for showed me other post that can be my reference.
    thanx to iPrank for gave me the source code for save from picture box to a file.
    really thanx for ur help. ^^
    @ iPrank: what do u mean with fancy control?

  7. #7
    PoorPoster iPrank's Avatar
    Join Date
    Oct 2005
    Location
    In a black hole
    Posts
    2,729

    Re: Picture Box, please?

    I meant some 3rd party controls that performs custom draw or uses another picturebox as container etc.

    (insert a picture in the picturebox, add a frame and run my code. )
    Usefull VBF Threads/Posts I Found . My flickr page .
    "I love being married. It's so great to find that one special person you want to annoy for the rest of your life." - Rita Rudner


  8. #8

    Thread Starter
    Junior Member
    Join Date
    Jun 2006
    Posts
    18

    Re: Picture Box, please?

    if i used an usercontrol in a picture box, what should i do?
    (cuz that usercontrol didn't show in bmp file)
    thanx in advance! ^^
    Last edited by weilee; Jun 10th, 2006 at 09:57 PM.

  9. #9

  10. #10
    PoorPoster iPrank's Avatar
    Join Date
    Oct 2005
    Location
    In a black hole
    Posts
    2,729

    Re: Picture Box, please?

    Problem with bitblt is, the picturebox must be fully visible on the desktop.
    Usefull VBF Threads/Posts I Found . My flickr page .
    "I love being married. It's so great to find that one special person you want to annoy for the rest of your life." - Rita Rudner


  11. #11
    Oi, fat-rag! bushmobile's Avatar
    Join Date
    Mar 2004
    Location
    on the poop deck
    Posts
    5,592

    Re: Picture Box, please?

    I'm assuming that's not a problem in this case - certainly nothing weilee has said would suggest so.

  12. #12
    PoorPoster iPrank's Avatar
    Join Date
    Oct 2005
    Location
    In a black hole
    Posts
    2,729

    Re: Picture Box, please?

    Quote Originally Posted by weilee
    if i used an usercontrol in a picture box, what should i do?
    (cuz that usercontrol didn't show in bmp file)
    thanx in advance! ^^
    Sorry, I haven't tried this code on usercontrol.

    for usercontrol, I don't know how to solve this issue.
    Quote Originally Posted by bushmobile
    I'm assuming that's not a problem in this case - certainly nothing weilee has said would suggest so.
    Yes. Looks like this is the correct option for this case.
    Usefull VBF Threads/Posts I Found . My flickr page .
    "I love being married. It's so great to find that one special person you want to annoy for the rest of your life." - Rita Rudner


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

    Re: Picture Box, please?

    Using BitBlt..
    VB Code:
    1. Option Explicit
    2.  
    3. Private Declare Function BitBlt Lib "gdi32" _
    4.     (ByVal hDCDest As Long, ByVal XDest As Long, ByVal YDest As Long, _
    5.     ByVal nWidth As Long, ByVal nHeight As Long, ByVal hDCSrc As Long, _
    6.     ByVal xSrc As Long, ByVal ySrc As Long, ByVal dwRop As Long) As Long
    7.  
    8. Private Sub Command1_Click()
    9.     BitBlt Picture2.hDC, 0, 0, Picture1.Width, Picture1.Height, Picture1.hDC, 0, 0, vbSrcCopy
    10.     SavePicture Picture2.Image, "C:\Test.bmp"  'Add here the path you want it to be saved
    11. End Sub
    12.  
    13. Private Sub Form_Load()
    14.     With Picture2
    15.         .AutoRedraw = True
    16.         .Width = Picture1.Width
    17.         .Height = Picture1.Height
    18.         .Visible = False
    19.     End With
    20. End Sub

  14. #14

    Thread Starter
    Junior Member
    Join Date
    Jun 2006
    Posts
    18

    Re: Picture Box, please?

    sorry. but i got a problem that iPrank mentioned.
    cuz the content of my picture box not fully visible.
    i have scroll bar to scroll the content of my picture box and
    i want to save all of the content of picture box into a file or print it.

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