Simple Screen Shot of all Multiple Monitors

I had a previous post on how to do this in VB. I’m boning up on my c# so I converted it by hand.

Story

Don’t you love it when you take a heaping mess of code and simplify it to it’s essence. It’s even better when you find code in libraries that you can use and delete your own. The less code you own the better. I went searching for a simple code sample to take a screen shot of all screens regardless of the configuration of the monitors. I couldn’t find anything small and easy. by the time I got done figuring it out I thought it should be out on the interwebs just to make it easier for the next guy.  Here it is:

using System;
using System.Drawing.Imaging;
using System.Windows;
using System.Drawing;

namespace Helpers
{
    class ScreenHelper
    {
        public static void SaveAllScreens( string fileName)
        {
            int screenWidth = Convert.ToInt32(SystemParameters.VirtualScreenWidth);
            int screenHeight = Convert.ToInt32(SystemParameters.VirtualScreenHeight);
            int screenLeft = Convert.ToInt32(SystemParameters.VirtualScreenLeft);
            int screenTop = Convert.ToInt32(SystemParameters.VirtualScreenTop);
            using (Bitmap bmp = new Bitmap(screenWidth, screenHeight, PixelFormat.Format32bppArgb))
            {
                using (Graphics gr = Graphics.FromImage(bmp))
                { 
                    gr.CopyFromScreen(screenLeft, screenTop, 0, 0, bmp.Size);
                    bmp.Save(fileName);
                }
            }
        }
    }
}

You can browse the project on Github.

That looks nice and easy. You will need references to System.Drawing if you are using WPF. This works even in the primary window is to the right of any other monitors making the area of the capture be negative. Hopefully this will help someone. Let me know if you have any suggestions.