Capturing/Drawing a Form to a Bitmap

J

judd

Hello:

I am looking for a way to create a bitmap image of a form
(containing various controls/graphics) which is not currently in
focus, or even minimized. One possible way that I believe may work is
to force that form to draw its entire contents into a bitmap instead
of a screen graphics context by capturing its PaintEventArgs.

Any help implementing this idea or other suggestions would be greatly
appreciated.

Thanks,

Judd
 
S

Stoitcho Goutsev \(100\) [C# MVP]

Hi Judd,

It is never been an easy task even with Win32 API. Taking snapshot of
visible form is not hard (you can't get away without using PInovke though),
if you need that code I can give you a sample how to do it.
Making form (or control) to paint itself in an arbitrary device contrex
(graphics object) though is different problem. In Win32 API there are
special messages for that. Take a look at WM_PRINT and WM_PRINTCLIENT. Those
are messages that is meant be used for this. However the controls needs to
respond to these messages. Unfortuantelly they don't have to. Since, all
standard windows controls handle those events correctly, this might not be
true for third party controls, though.

Once I gave a quick try to use them with .NET. I'd no success, but I believe
there is a workaround the problems I had. So, give it a try they might help
you.
 

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