views:

208

answers:

2

Okay, here's what I'm trying to do. First I'll explain the end result I'm trying to achieve in case there are other ideas on how to do this.

I'm making a screen capture utility that takes a screen shot of only one window... my window (which I have total programmatic control over). However, this window may be much larger than the desktop of the computer on which the utility will run. The height, in particular, may reach several thousand pixels on a computer with 1024x768 resolution.

So I'm trying to capture the full window even though it's much larger than the screen. That's the end result I'm trying to achieve.

One hypothetical solution to this is to render the form/control on a graphics or screen object of some sort, and take the screen shot off of that object, instead of taking a screen shot of the physical desktop.

Essentially I need to draw controls on an imaginary screen that exists only in code and memory and I don't even know what to search for, so even ideas on what to put into Google (the TRUE search engine) would be helpful.

Any ideas? Thanks in advance!

EDIT: I'm using WinForms.

+1  A: 

You didn't mention which technology your C# application uses, I'm assuming it's either WinForms or WPF.

If your implementation uses WPF, you could simply render it to a DrawingImage with the right dimensions - or even use the printing capabilities of WPF to "print" the contents of the window to an image in memory. Here's a decent example of printing in WPF that you may be able to adapt (if you're using WPF).

With a WinForms application, it is a bit trickier, because WinForm controls don't always scale well under higher resolutions, and can exhibit alignment problems. Here's a link that describes printing a WinForm screen to an image. It demonstrates printing a UserControl, but you should be able to adapt the implementation for your purposes.

LBushkin
Checked it out again, and it works! :) Thanks a bunch!
Helgi Hrafn Gunnarsson
+1  A: 

Hmm, that's very odd. Have you actually written this form yet? The Form class is extremely insistent that its Size can never be larger than the screen. I've never found a workaround for this and have never seen one posted in a WF related forum.

Anyhoo, you can't make a screen shot because you don't have enough screen. The only other option is Control.DrawToBitmap().

"Several thousands of pixels" is liable to get you into trouble with OutOfMemory exceptions on 32-bit operating systems when you try to create the bitmap. Not because you don't have enough memory but because there isn't an empty hole left in the virtual memory address space that is large enough to fit the bitmap The only good workaround for that is a 64-bit operating system.

Hans Passant
A 64-bit OS requirement is fine. This is for a server. :) I've tried messing around with Control.DrawToBitmap() to no avail. It simply doesn't draw anything, although the article pointed to by LBushkin is written by someone who apparently got it working. I've copied his exact steps but I just get a black picture. Thanks for the comment though.
Helgi Hrafn Gunnarsson
Post your code.
Hans Passant