|
-
Jun 9th, 2006, 09:30 AM
#1
Thread Starter
Junior Member
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..
-
Jun 9th, 2006, 09:48 AM
#2
Addicted Member
Re: Picture Box, please?
VB Code:
Private Sub Command1_Click()
With CommonDialog1
.DialogTitle = "Save"
.Filter = Picture (*.bmp)|*.bmp
.ShowSave
SavePicture PictureBox1.Image, .FileName
End With
End Sub
Last edited by Redangel; Jun 9th, 2006 at 09:48 AM.
Reason: Code Tags
-
Jun 9th, 2006, 10:06 AM
#3
Thread Starter
Junior Member
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...
-
Jun 9th, 2006, 10:18 AM
#4
Hyperactive Member
-
Jun 9th, 2006, 10:31 AM
#5
Re: Picture Box, please?
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
-
Jun 9th, 2006, 10:51 AM
#6
Thread Starter
Junior Member
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?
-
Jun 9th, 2006, 10:57 AM
#7
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. )
-
Jun 10th, 2006, 09:27 PM
#8
Thread Starter
Junior Member
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.
-
Jun 11th, 2006, 04:49 AM
#9
-
Jun 11th, 2006, 04:58 AM
#10
Re: Picture Box, please?
Problem with bitblt is, the picturebox must be fully visible on the desktop.
-
Jun 11th, 2006, 04:59 AM
#11
Re: Picture Box, please?
I'm assuming that's not a problem in this case - certainly nothing weilee has said would suggest so.
-
Jun 11th, 2006, 05:06 AM
#12
Re: Picture Box, please?
 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. 
 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.
-
Jun 11th, 2006, 05:10 AM
#13
Re: Picture Box, please?
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
-
Jun 11th, 2006, 06:24 AM
#14
Thread Starter
Junior Member
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|