title: PrintScreen only active window
body: <p>I'm writing a simple Windows Forms utility to screenshot either the entire screen or an active window and save the file. The winform has a button called 'Capture' that, when clicked, takes the screenshot.</p>
  
  <p>I have the code entirely working for the entire screen but can't figure it out for the active window.</p>
  
  <p>By my current code, if I select 'Active Window', it ends up Print Screening the application itself which isn't what I want.</p>
  
  <p>Here's my code (under the Capture_Click method):</p>
  
  <pre><code>try
          {
              this.Hide();
  
              bmpScreenshot = new Bitmap(Screen.PrimaryScreen.Bounds.Width, Screen.PrimaryScreen.Bounds.Height, PixelFormat.Format32bppArgb);
              //bmpScreenshot = new Bitmap(this.Bounds.Width, this.Bounds.Height, PixelFormat.Format32bppArgb);
  
              gfxScreenshot = Graphics.FromImage(bmpScreenshot);
  
              if (AltPrint.Checked)
              {
                  gfxScreenshot.CopyFromScreen(this.Bounds.X, this.Bounds.Y, 0, 0, this.Bounds.Size, CopyPixelOperation.SourceCopy);
              }
              else
              {
                  gfxScreenshot.CopyFromScreen(Screen.PrimaryScreen.Bounds.X, Screen.PrimaryScreen.Bounds.Y, 0, 0, Screen.PrimaryScreen.Bounds.Size, CopyPixelOperation.SourceCopy);
              }
  
              bmpScreenshot.Save(SaveLocation, ImageFormat.Png);
  
              number++;
          }
  </code></pre>