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..
Printable View
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..
VB Code:
Private Sub Command1_Click() With CommonDialog1 .DialogTitle = "Save" .Filter = Picture (*.bmp)|*.bmp .ShowSave SavePicture PictureBox1.Image, .FileName End With End Sub
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...
Try to see if this thread will be of any help
http://www.vbforums.com/showthread.p...handle+picture
If you don't have any other 'child' picturebox or some fancy control, the following code may work:
VB Code:
' Add another PictureBox (Picture2) in your form Option Explicit Private Declare Function SendMessage Lib "user32" _ Alias "SendMessageA" ( _ ByVal hwnd As Long, _ ByVal wMsg As Long, _ ByVal wParam As Long, _ ByVal lParam As Long) As Long Const WM_PAINT = &HF Const WM_PRINT = &H317 Const PRF_CLIENT = &H4& ' Draw the window's client area Const PRF_CHILDREN = &H10& ' Draw all visible child Const PRF_OWNED = &H20& ' Draw all owned windows Private Sub Command1_Click() Picture2.Cls SendMessage Picture1.hwnd, WM_PAINT, Picture2.hDC, 0 SendMessage Picture1.hwnd, WM_PRINT, Picture2.hDC, PRF_CHILDREN + PRF_CLIENT + PRF_OWNED SavePicture Picture2.Image, "c:\Test.bmp" End Sub Private Sub Form_Load() Picture2.Visible = False Picture2.AutoRedraw = True Picture2.Width = Picture1.Width Picture2.Height = Picture1.Height End Sub
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?
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. ;) )
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! ^^
you can use BitBlt, see this post: http://www.vbforums.com/showthread.php?t=392973
Problem with bitblt is, the picturebox must be fully visible on the desktop. :(
I'm assuming that's not a problem in this case - certainly nothing weilee has said would suggest so.
Sorry, I haven't tried this code on usercontrol.Quote:
Originally Posted by weilee
for usercontrol, I don't know how to solve this issue. :(
Yes. Looks like this is the correct option for this case.Quote:
Originally Posted by bushmobile
Using BitBlt..
VB Code:
Option Explicit 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() BitBlt Picture2.hDC, 0, 0, Picture1.Width, Picture1.Height, Picture1.hDC, 0, 0, vbSrcCopy SavePicture Picture2.Image, "C:\Test.bmp" 'Add here the path you want it to be saved End Sub Private Sub Form_Load() With Picture2 .AutoRedraw = True .Width = Picture1.Width .Height = Picture1.Height .Visible = False End With End Sub
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.