How do I copy a Form's image to a bitmap? – And do so before it gets to the screen.

S

Stan Shankman

C# -- Visual Studio.Net – Windows Application

Greetings all,

How do I copy a Form’s image to a bitmap? – And do so before it gets to the screen.

I haven’t been able to find anyone that knows how to do this - - all I want to do is copy a Form’s image to a bitmap. - - In effect,
I want to take a window-shot of a Form, (as opposed to a “screen-shot”) but it must be done before that Form hits the screen.

Anyone? Ideas?

Thanks all,
-Stan Shankman
 
B

Bob Powell [MVP]

You cannot. The form has to be drawn on the screen before you can capture
it's image.

--
Bob Powell [MVP]
C#, System.Drawing

The November edition of Well Formed is now available.
Learn how to create Shell Extensions in managed code.
http://www.bobpowell.net/currentissue.htm

Answer those GDI+ questions with the GDI+ FAQ
http://www.bobpowell.net/gdiplus_faq.htm

Read my Blog at http://bobpowelldotnet.blogspot.com

Stan Shankman said:
C# -- Visual Studio.Net - Windows Application

Greetings all,

How do I copy a Form's image to a bitmap? - And do so before it gets to the screen.

I haven't been able to find anyone that knows how to do this - - all I
want to do is copy a Form's image to a bitmap. - - In effect,
I want to take a window-shot of a Form, (as opposed to a "screen-shot")
but it must be done before that Form hits the screen.
 
S

Stan Shankman

How do I copy a Form's image to a bitmap? - And do so before it gets to
the screen. - Stan
You cannot. The form has to be drawn on the screen before you can capture
it's image.> - Bob

Thanks for the replay Bob, but let me ask you this: Would there be anyway to fake it that you know of? You know, some way to built a
"soft screen" - - a place in memory that I can "trick" the system into thinking is the real screen - - that sort of thing.
- Stan Shankman
 
B

Byron Cullen

Stan,

Maybe you could run the program one time and let the controls draw with the
default values that you desire and then alt-printscreen a screenshot of your
form. Then edit the bitmap to clip just the client area out of the
screenshot and save that as a resource in your project.

Then you will have access to the pseudo form before it's initial paint. That
is assuming that your form is always the same size and layout when it is
first displayed.

Something else to look into is maybe drawing the form on a back buffer. I'm
not sure if this can be done but I reason that if a control can be double
buffered then a form _may_ be coerced into drawing itself to an off-screen
hDC or Graphics object. I've not done this before but it would be worth
looking into.

Byron Cullen
ThunderTools

Stan Shankman said:
Thanks for the replay Bob, but let me ask you this: Would there be anyway
to fake it that you know of? You know, some way to built a
"soft screen" - - a place in memory that I can "trick" the system into
thinking is the real screen - - that sort of thing.
 
S

Stan Shankman

Byron,



Hey guy, thanks for the thoughts. The problem with letting the program draw the Form one time, is that it just won't work - because,
for one thing, the form keeps on changing. But also because allowing the form to make brief "appearances" before its "time" will be
cosmetically fouling to the overall screen presentation I'm trying to bring about.



Now on the other hand, that "back-buffer" idea of yours just might be a winner. The only problem is, I haven't a clue about how to
go about implementing such a scheme.



So, if anyone is monitoring this thread, and has anything to add, please feel free to jump in.



I know that MVP Bob Powell says it can't be done, -- and I'm not doubting his integrity on the matter. So excuse me if I hold out
faith that some down-and-dirty assembler trick or other can come along and get the job done. Sure, it may not be easy, but then
putting a million transistors on an integrated circuit and wiring them together weren't no simple trick either.



That's one small step for man . . .



- Stan Shankman
 
B

Byron Cullen

Stan,

Yeah Bob knows mystical things it seems :)

Going back to C++ days I remember you could use the CWindow::print command
to have the window draw itself on the specified device context but I am too
new of a fish in the .NET waters to know where to start looking for
something similar. But maybe just saying that will spark an idea for
someone.

Here's another hack of an idea, but I'm not sure if it will work of course:

Set your window position somewhere entirely off screen and let the form draw
there (out of sight) then capture the Graphics object. Just a thought... I'm
a little fuzzy on the 'presentation' you are trying to accomplish so I may
be barking up the wrong dog again.

Byron Cullen
ThunderTools

Stan Shankman said:
Byron,



Hey guy, thanks for the thoughts. The problem with letting the program
draw the Form one time, is that it just won't work - because,
for one thing, the form keeps on changing. But also because allowing the
form to make brief "appearances" before its "time" will be
cosmetically fouling to the overall screen presentation I'm trying to bring about.



Now on the other hand, that "back-buffer" idea of yours just might be a
winner. The only problem is, I haven't a clue about how to
go about implementing such a scheme.



So, if anyone is monitoring this thread, and has anything to add, please feel free to jump in.



I know that MVP Bob Powell says it can't be done, -- and I'm not doubting
his integrity on the matter. So excuse me if I hold out
faith that some down-and-dirty assembler trick or other can come along and
get the job done. Sure, it may not be easy, but then
putting a million transistors on an integrated circuit and wiring them
together weren't no simple trick either.
 

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