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:
Imports System.Drawing Imports System.Windows.Forms Imports System.Drawing.Imaging Imports System.Windows.SystemParameters Public Class ScreenHelper Shared Sub SaveAllScreens(ByVal FileName As String) Using bmp As New Bitmap(VirtualScreenWidth, VirtualScreenHeight, Imaging.PixelFormat.Format32bppArgb) Using gr As Graphics = Graphics.FromImage(bmp) gr.CopyFromScreen(VirtualScreenLeft, VirtualScreenTop, 0, 0, bmp.Size) bmp.Save(FileName) End Using End Using End Sub End Class
That looks nice and easy. You will need references to System.Drawing and System.Windows.Forms 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.