[RESOLVED] Capture Picture Of A Form When A Portion Of It Is Off The Screen...
I can capture a picture of the form and put it on the clipboard perfectly... except the portion that's off the screen. If my form is wider than the screen is, it takes that portion of the picture and just makes it black when I paste it into something like PaintBrush. I've even tried saving it, as opposed to just putting it on the clipboard... same result. Any way to capture a picture of the entire form without blacking out the portion that's off the screen?
Re: Capture Picture Of A Form When A Portion Of It Is Off The Screen...
Try this, first add a PictureBox to your Form and make it invisible, then add this code (I used a CommandButton to capture)
Code:
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
Private Const WM_PAINT = &HF
Private Const WM_PRINT = &H317
Private Const PRF_CLIENT = &H4& ' Draw the window's client area
Private Const PRF_CHILDREN = &H10& ' Draw all visible child
Private Const PRF_OWNED = &H20& ' Draw all owned windows
Private Sub Command1_Click()
Dim rv As Long
Clipboard.Clear
Picture1.Width = Me.Width
Picture1.Height = Me.Height
Picture1.AutoRedraw = True
rv = SendMessage(Me.hwnd, WM_PAINT, Picture1.hDC, 0)
rv = SendMessage(Me.hwnd, WM_PRINT, Picture1.hDC, PRF_CHILDREN + PRF_CLIENT + PRF_OWNED)
Set Picture1.Picture = Picture1.Image
Clipboard.SetData Picture1.Picture, vbCFBitmap
End Sub
This should add the complete Form Picture to Clipboard with offscreen parts included. Just ensure the Form use twips as Scalemode, if not a little coordinate conversion would be needed.
Re: [RESOLVED] Capture Picture Of A Form When A Portion Of It Is Off The Screen...
I don't know how yours turned out but when I try it I get a black rectangle on the left side of the client area and it chops off part of the top of the client area. I used that code exactly as is, I made the picturebox invisible.
Anything I post is an example only and is not intended to be the only solution, the total solution nor the final solution to your request nor do I claim that it is. If you find it useful then it is entirely up to you to make whatever changes necessary you feel are adequate for your purposes.
Re: [RESOLVED] Capture Picture Of A Form When A Portion Of It Is Off The Screen...
Originally Posted by jmsrickland
I don't know how yours turned out but when I try it I get a black rectangle on the left side of the client area and it chops off part of the top of the client area. I used that code exactly as is, I made the picturebox invisible.
Could you attach an example project so i can see what's happening? The problem could be a control in the Form or the Form's properties or many other things, so if you attach an small project it will be easier.
Re: Capture Picture Of A Form When A Portion Of It Is Off The Screen...
jcis,
I am trying to capture a form - part of which is off-screen; your code and code below I am using does capture the whole form... BUT some parts of the form are out of place and it does not capture a RichText Box information; my code below
Clipboard.Clear
picDest.AutoRedraw = True
picDest.ScaleMode = 1 '- Twip
picDest.Width = Me.Width
picDest.Height = Me.Height