Link to home
Start Free TrialLog in
Avatar of cymru_cowboy
cymru_cowboy

asked on

Create an image of the form

Hi, is it possible to create an image of a form and save it as an image to go in a picture box or image control.
I was thinking there must be a priunt screen sort of command that could be sent a forms handle as an argument.

Hope it's as easy as that but I doubt it

Cheers
ASKER CERTIFIED SOLUTION
Avatar of JNSTAUB
JNSTAUB
Flag of France image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
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
Private Const SRCCOPY = &HCC0020 ' (DWORD) dest = source


Private Sub Command1_Click()

Dim retVal As Integer
Picture1.Visible = False
Picture1.AutoRedraw = True
Picture1.ScaleMode = 3
Picture1.Width = Me.ScaleWidth
Picture1.Height = Me.ScaleHeight

'' now write to Picture1r hdc
retVal = BitBlt(Picture1.hDC, 0, 0, Me.ScaleWidth, Me.ScaleHeight, _
        Me.hDC, 0, 0, SRCCOPY)

Picture1 now holds the image of the form (make it visible if you want to see)
Avatar of cymru_cowboy
cymru_cowboy

ASKER

Really sorry I haven't had a chance to test this code, I will be using it shortly however given half a chance. Until then I'll award the points to JNSTAUB for getting in their first.
But thanks to bobbit31 for the help as well