I want to make an SS application. But I have problem on this subject. I want user to be able to select a special area to take screenshot. I also want the desktop is live while the user is selecting the area. For example user wants to take an SS of a video's specific frame. The user must be able to do this while video is playing. I have tried this using drawing directly on the desktop. But it flickers so much. How can I fix this or is there an alternative way to do?
My code :
[DllImport("User32.dll")]
static extern IntPtr GetDC(IntPtr hwnd);
[DllImport("user32.dll")]
static extern bool InvalidateRect(IntPtr hWnd, IntPtr lpRect, bool bErase);
public Form1()
{
InitializeComponent();
this.Load += Form1_Load;
}
void Form1_Load(object sender, EventArgs e)
{
Start();
}
IntPtr handle;
Graphics grp;
void Start()
{
handle = GetDC(IntPtr.Zero);
grp = Graphics.FromHdc(handle);
grp.SmoothingMode = SmoothingMode.HighQuality;
timer2.Start();
}
private void timer2_Tick(object sender, EventArgs e)
{
grp.DrawLine(Pens.Red, 0, Cursor.Position.Y, Screen.PrimaryScreen.Bounds.Width, Cursor.Position.Y);
InvalidateRect(IntPtr.Zero, IntPtr.Zero, false);
}