Site hosted by Angelfire.com: Build your free website today!

Save an image from PictureBox (playing as container for others controls)

Level: Intermediate

Save an image from MSChart Control

This job have been asking at EE several trimes.
Until now, i wasn't unable to figure out the whole thing. Strangelly, i found it looking for something else.
To make this project we will need a Standard Exe Project, a form (Form1) with two PictureBox controls (Picture1 and Picture2 would be fine :). Set all .ScaleMode property to 3 - vbPixel.
We need to use a little API function to do the job, so, let go to General Declarations section of Form1 and paste this code:
Private Declare Function BitBlt Lib "gdi32" (ByVal hDestDC As Long, ByVal x As Long, ByVal y As Long, ByVal nWidth As Long, ByVal nHeight As Long, ByVal hSrcDC As Long, ByVal xSrc As Long, ByVal ySrc As Long, ByVal dwRop As Long) As Long
We need to set .Autoredraw property to True for Picture2 (this is important).
Add some image as background for Picture1 and several controls inside it, just to simulate a container.
The form should look like this:



The main processing is done at Form1_Click event, you could use other.
Private Sub Form_Click()
With Picture2
   BitBlt .hDC, 0, 0, .ScaleWidth, .ScaleHeight, Picture1.hDC, 0, 0, vbSrcCopy
   SavePicture .Image, "C:\myfullpic.bmp"
End With
End Sub
After clicking on Form1, it should looks so:



OK, just go to Explorer window and open C:\myfullpic.bmp with a double-click.

Hope you have enjoyed that work as i did.
;)


©2003 - Richie Simonetti