title: Screen Capture program in VB.NET
body: <p>I had created an application that captures the screenshot of desktop screen. It works very well with button I have used in form. But now I want to make that thing works automatically using timers but whenever I try to run program <code>NullReferenceException</code> occur can any one tell me whats going wrong here.</p>
  
  <pre><code>TimerCapture interval=5
  
  TimerSave interval=6
  </code></pre>
  
  <p>Here is the code can tell you the scenario:</p>
  
  <pre><code>Public Class Form1
  
  
      Private Sub timerCapture_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles timerCapture.Tick
          Dim bounds As Rectangle
          Dim screenshot As System.Drawing.Bitmap
          Dim graph As Graphics
          bounds = Screen.PrimaryScreen.Bounds
          screenshot = New System.Drawing.Bitmap(bounds.Width, bounds.Height, System.Drawing.Imaging.PixelFormat.Format32bppArgb)
          graph = Graphics.FromImage(screenshot)
          graph.CopyFromScreen(bounds.X, bounds.Y, 0, 0, bounds.Size, CopyPixelOperation.SourceCopy)
          PictureBox1.Image = screenshot
      End Sub
  
  
  
  
      Private Sub timerSave_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles timerSave.Tick
          Me.PictureBox1.Image.Save("d:\\capture.bmp")
  
      End Sub
  
      Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
  
          ' Me.WindowState = FormWindowState.Minimized
  
          'Me.ShowInTaskbar = False
  
      End Sub
  
      Private Sub timerClose_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles timerClose.Tick
          Me.Close()
  
      End Sub
  
      Private Sub capture_btn_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles capture_btn.Click
          Dim bounds As Rectangle
          Dim screenshot As System.Drawing.Bitmap
          Dim graph As Graphics
          bounds = Screen.PrimaryScreen.Bounds
          screenshot = New System.Drawing.Bitmap(bounds.Width, bounds.Height, System.Drawing.Imaging.PixelFormat.Format32bppArgb)
          graph = Graphics.FromImage(screenshot)
          graph.CopyFromScreen(bounds.X, bounds.Y, 0, 0, bounds.Size, CopyPixelOperation.SourceCopy)
          PictureBox1.Image = screenshot
      End Sub
  
      Private Sub save_btn_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles save_btn.Click
          Me.PictureBox1.Image.Save("d:\\capture.bmp")
      End Sub
  End Class
  </code></pre>
  
  <p>Thanks in advance....</p>