public static Bitmap CaptureScreen() { int hdcSrc = User32.GetWindowDC(User32.GetDesktopWindow()), // Get a handle to the desktop window hdcDest = GDI32.CreateCompatibleDC(hdcSrc), // Create a memory device context hBitmap = GDI32.CreateCompatibleBitmap(hdcSrc, // Create a bitmap and place it in the memory DC GDI32.GetDeviceCaps(hdcSrc, 8), GDI32.GetDeviceCaps(hdcSrc, 10)); // GDI32.GetDeviceCaps(hdcSrc,8) returns the width of the desktop window // GDI32.GetDeviceCaps(hdcSrc,10) returns the height of the desktop window GDI32.SelectObject(hdcDest, hBitmap); // Required to create a color bitmap GDI32.BitBlt(hdcDest, 0, 0, GDI32.GetDeviceCaps(hdcSrc, 8), // Copy the on-screen image into the memory DC GDI32.GetDeviceCaps(hdcSrc, 10), hdcSrc, 0, 0, 0x00CC0020); Bitmap bitmapa = new Bitmap(Image.FromHbitmap(new IntPtr(hBitmap)), Image.FromHbitmap(new IntPtr(hBitmap)).Width, Image.FromHbitmap(new IntPtr(hBitmap)).Height); Cleanup(hBitmap, hdcSrc, hdcDest); // Free system resources return(bitmapa); }