Click here to Skip to main content
15,899,026 members
Please Sign up or sign in to vote.
5.00/5 (1 vote)
See more:
hi!
i have created an app that takes a screen shot of my desktop after clicking on the button.here is the code:

C#
private void button1_Click(object sender, EventArgs e)
       {
           this.Hide();
           timer1.Start();
       }

       private void timer1_Tick(object sender, EventArgs e)
       {
           Bitmap b = new Bitmap(ScreenWidth, ScreenHeight);
           g = Graphics.FromImage(b);
           g.CopyFromScreen(Point.Empty, Point.Empty, Screen.PrimaryScreen.Bounds.Size);
           pictureBox1.Image = b;
           this.Show();
           button2.Enabled = true;
           timer1.Stop();
       }






what i want is to make it automatic. so that it automatically takes the desktop screen shot after every 5 minutes.
please tell me how to do it.
thanks in advance
Posted
Comments
[no name] 16-Apr-12 9:48am    
Seriously? Start your timer in the form load event.
El_Codero 16-Apr-12 9:52am    
I think OP's "serious" problem is to take a screenshot every 5 minutes :) Regards

1 solution

Hi,

use the DispatcherTimer Class with TimeSpan property, optionally you could run your application as a windows service.

DispatcherTimer:
http://msdn.microsoft.com/de-de/library/system.windows.threading.dispatchertimer.aspx[^]

Create a windows service:
Creating a Basic Windows Service in C#[^]

With Best Regards
 
Share this answer
 
v2
Comments
Mehdi Gholam 16-Apr-12 10:08am    
Windows services do not have access to desktops, so creating one will be useless.
El_Codero 16-Apr-12 10:16am    
Hi, there are some workarounds to achieve this (more workaround with win 7,easier with XP). Please have a look at this threads.
http://stackoverflow.com/questions/1002064/screen-capture-from-windows-service
http://stackoverflow.com/questions/1832384/c-capture-screen-from-windows-service
Maybe a little bit overdriven for OP, but maybe needed ;). Best Regards
saifullahiit 16-Apr-12 11:09am    
i haven't got any idea from given links:(
have some other suggestions?
El_Codero 16-Apr-12 11:15am    
depends what your requirement is. if you don't want to use a windows service for making screenshots, it's easy to achieve doing screenshots with DispatcherTimer I wrote above ;) don't hesitate to ask if something is still unclear for you.With Best Regards

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900