Capture whole child form in VB.Net

G

Guest

I created a child form that is much bigger than the MDI form in VB.Net. I am
trying to capture the whole child form and save as an image or sent to
printer. I tried to use BitBlt to capture the child form but I can only
capture the visible part of the child form whatever you scroll to any part of
the form. I have read the article in site
http://www.fengyuan.com/article/wmprint.html unforturely it is for C++
instead of VB.Net. I tried to use the same way in VB.Net but failed. Is there
a way in VB.Net to capture whole child form including the part that you have
to scroll to to see? Please Help.

Thanks a lot.

Jack
 
G

Guest

You should be able to create a new bitmap the size of the form and use
myform.CreateGraphics to create a graphics object. The graphics object can
then be copied onto the bitmap using bitblt...This should work.
 
G

Guest

Thanks Dennis, I tried what you suggeted and I still could not capture the
whole child form. My code is as following. I don't know what is wrong with
code. Please help. Thanks again.

Dim MyGraphics As Graphics = ChildForm.CreateGraphics()

Dim s As Size = ChildForm.ClientSize
Dim ChildFormBitmap As Bitmap
ChildFormBitmap = New Bitmap(s.Width, s.Height)
Dim MemoryGraphics As Graphics = Graphics.FromImage(ChildFormBitmap)

Dim dc1 As IntPtr = MyGraphics.GetHdc
Dim dc2 As IntPtr = MemoryGraphics.GetHdc

BitBlt(dc2, 0, 0, s.Width, s.Height, dc1, 0, 0, SRCCOPY)

MyGraphics.ReleaseHdc(dc1)
MemoryGraphics.ReleaseHdc(dc2)

Return ChildFormBitmap

Jack
 
G

Guest

What size does s result in, i.e., is it the size of your form?

What size does Memory Graphics end up as?

What is copied to you bitmap?
 
G

Guest

S is the client size of the child form.
Memory Graphics end up with S size.
The code copies child form to bitmap by DC.
The problem is that the DC only capture the visible part of the child form.
It is not a size issue. The child form can be several times bigger than the
screen.
 
G

Guest

hmmm...it must be that when the graphics object is created for the form, it
only creates a graphis object for the visible portion of the form...what a
bummer! There must be a way to do it. You might try double buffering but
you'd have to draw the form yourself in the paint event and this, I suspect
would end up with the same result. I'll keep this thread on my hot list and
investigate a bit further.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top