Search code examples
c#winformsscreenshot

Screenshot from second screen


Hi I am working on a program where the user can take screenshots. The users can choose whether they want to take a screenshot from screen 1,2,3 or 4. I know how to get out the first screenshot from the first screen, but how do I get the images from screen 2,3 and 4?

My code to get the screenshot from the first screen looks like this:

 private void btnScreenOne_Click(object sender, EventArgs e) 
 {
     Bitmap bitmap = new Bitmap(Screen.PrimaryScreen.Bounds.Width,
         Screen.PrimaryScreen.Bounds.Height);

     Graphics graphics = Graphics.FromImage(bitmap as Image);

     graphics.CopyFromScreen(0, 0, 0, 0, bitmap.Size);

     bitmap.Save(@"C:\Users\kraqr\Documents\PrintScreens\" + 
        DateTime.Now.ToString("yyyy-MM-dd_HH-mm-ss") + " Screen1" + 
        ".bmp", ImageFormat.Bmp);

}

Grateful for answers.


Solution

  • The Screen class has a static property AllScreens which gives you an array of screens. Those objects have a Bounds property which you can surely use ...

    Long story short: You initialize the bitmap with the size of the desired screen (don't use PrimaryScreen, because that's only the primary one, as the name implies) and then pass the appropriate boundaries to CopyFromScreen.