1

I'm quite new to the world of programing and have an issue with trying to do a print screen of my program (saving to my desktop as a png) the closest I've gotten to it is to manage to save a screenshot of my entire screen.

The coding I've used is as follows:

Bitmap printscreen = new Bitmap(Screen.PrimaryScreen.Bounds.Height, Screen.PrimaryScreen.Bounds.Width);
Graphics graphics = Graphics.FromImage(printscreen as Image);
graphics.CopyFromScreen(0, 0, 0, 0, printscreen.s);
printscreen.Save(@"C:\Payroll\" + txtName.Text + "_Payroll_" + dateTimePicker1.Text + ".png", ImageFormat.Png);

And I can't figure out if there's any way to do what I want it to.

Any help greatly appreciated.

Manfred Radlwimmer
  • 13,257
  • 13
  • 53
  • 62
  • 3
    Why not just restrict the size to your window? and its location? – BugFinder May 25 '16 at 11:14
  • [winforms](http://stackoverflow.com/q/5124434/1997232)? [wpf](http://stackoverflow.com/q/24466482/1997232) ? – Sinatr May 25 '16 at 11:19
  • Possible duplicate. It looks like you want to capture the Active window. Please see this thread: http://stackoverflow.com/questions/1163761/capture-screenshot-of-active-window – Ryan Peters May 25 '16 at 11:27
  • Seems this is more in depth involving Interop and Win32 api calls. There are many examples all of which do something similar to the following tutorial: http://www.codeproject.com/Articles/19192/How-to-capture-a-Window-as-an-Image-and-save-it – Ryan Peters May 25 '16 at 11:43

0 Answers0