using System;
using System.Data;
using System.Diagnostics;
using System.Drawing;
using System.Runtime.InteropServices;
using System.Threading;
using System.Windows.Forms;
namespace HardCopy
{
public partial class HardCopy : Form
{
Bitmap screenShotBMP;
Rectangle rect = new Rectangle();
[DllImport("user32.dll")]
static extern IntPtr GetForegroundWindow();
[DllImport("user32.dll", SetLastError = true)]
static extern bool GetWindowRect(IntPtr hWnd, out Rectangle lpRect);
[StructLayout(LayoutKind.Sequential)]
public struct RECT
{
public int Left;
public int Top;
public int Right;
public int Bottom;
}
public HardCopy()
{
InitializeComponent();
}
private void Form1_Load(object sender, EventArgs e)
{
this.Hide();
Thread.Sleep(200);
GetWindowRect(GetForegroundWindow(), out rect);
screenShotBMP = new Bitmap(rect.Width - rect.X, rect.Height - rect.Y);
using (Graphics gr = Graphics.FromImage(screenShotBMP))
{
gr.CopyFromScreen(rect.Location, Point.Empty, rect.Size);
}
pictureBox1.Image = screenShotBMP;
this.Show();
}
}
}