This is a Windows application using C#. I want to capture a screen shot with a timer. The timer is set to a 5000 ms interval. As the timer is started, the desktop screen should be captured with the source window caption.
try
{
System.Windows.Forms.Timer timer = new System.Windows.Forms.Timer();
timer.Tick += new EventHandler(timer2_Tick);
timer.Interval = (100) * (50);
timer.Enabled = true;
timer.Start();
ScreenShots sc = new ScreenShots();
sc.pictureBox1.Image = system_serveillance.CaptureScreen.GetDesktopImage();
while(sc.pictureBox1.Image != null)
{
sc.pictureBox1.Image.Save("s"+".jpg", System.Drawing.Imaging.ImageFormat.Jpeg);
sc.pictureBox1.Image = null;
}
This code is not working properly. How can I make it work?
The timer isn’t firing because you’re not handling the tick event. Pete has also pointed out your file will be overwritten on each tick.
It needs to look something more like the following. This isn’t the exact code but it should give you an idea.