[Mono-dev] How do I take a screenshot?

Robert Jordan robertj at gmx.net
Sat Jul 23 12:53:54 EDT 2011


On 23.07.2011 03:04, killer1390 wrote:
> Plain and simple. I would like to be able to take a screen shot which I can
> then place inside a picturebox. The closest I have come to is this:
> http://stackoverflow.com/questions/5243021/how-to-take-screenshot-from-panel-in-mono-c
> Link
>
> This would work, but it doesn't resize, and it is really slow to do it.
> Is there a better way?

Slow? Doesn't resize? Are we looking at the same code snippet?

Anyway, since PictureBox is a WinForms control, you can take screenshots
using Graphics.CopyFromScreen, like under Windows:

var screenRect = Screen.FromControl (this).Bounds;
var bitmap = new Bitmap (screenRect.Width, screenRect.Height);
using (var g = Graphics.FromImage (bitmap)) {
	g.CopyFromScreen (
		screenRect.Left, screenRect.Top,
		0, 0,
		screenRect.Size);
}
pictureBox.Image = bitmap;


Robert



More information about the Mono-devel-list mailing list