Make a counter and then assign counter value to the filename.
Note 1: Bitmap
parent class Image
implements IDisposable
interface so you could enclose the Bitmap
class declaration within using block
to make sure its disposal.
Note 2: Graphics
class implements IDisposable
interface so you could enclose the Graphics
class declaration within using block
to make sure its disposal.
Try This:
int counter = 0;
private void timer1_Tick(object sender, EventArgs e)
{
counter =counter+1;
GetScreenShot(counter);
email.Send("HAMMAD");
MessageBox.Show("DONE");
}
private static void GetScreenShot(int counter)
{
using(Bitmap bitmap = new Bitmap(Screen.PrimaryScreen.Bounds.Width,
Screen.PrimaryScreen.Bounds.Height))
{
using(Graphics graphics = Graphics.FromImage(bitmap as Image))
{
graphics.CopyFromScreen(0, 0, 0, 0, bitmap.Size);
}
bitmap.Save("screenshot"+counter+".jpeg", ImageFormat.Jpeg);
}
}
EDIT: for sending proper screenshot in email try this:
private void timer1_Tick(object sender, EventArgs e)
{
counter =counter+1;
GetScreenShot(counter);
email.Send("screenshot"+counter+".jpeg");
MessageBox.Show("DONE");
}