0

I have an application A that is made in WPF and WinForms.I have written another Application in WinForms for Capturing Screen. The problem I'm facing is that The dialog boxes that come up in Application A do not captured in the screen. The whole screen gets captured including the area behind the dialog box but the dialog box doesn't get captured.

    public void CaptureScreen(string filepath)
    {

        string[] words = filepath.Split('\\');
        string newFilePath = " ";
        foreach (string word in words)
        {
            if (!(word.Contains(".bmp")))
            {
                newFilePath = newFilePath + word + "//";
            }
            else
            {
                newFilePath = newFilePath + word;
            }


        }

        this.WindowState = FormWindowState.Minimized;


        Screen[] screens;
        screens = Screen.AllScreens;
        int noofscreens = screens.Length, maxwidth = 0, maxheight = 0;
        for (int i = 0; i < noofscreens; i++)
        {
            if (maxwidth < (screens[i].Bounds.X + screens[i].Bounds.Width)) maxwidth = screens[i].Bounds.X + screens[i].Bounds.Width;
            if (maxheight < (screens[i].Bounds.Y + screens[i].Bounds.Height)) maxheight = screens[i].Bounds.Y + screens[i].Bounds.Height;
        }


        var width = maxwidth;
        var height = maxheight;

        Point sourcePoint = Point.Empty;
        Point destinationPoint = Point.Empty;

        Rectangle rect = new Rectangle(0, 0, width, height);

        Bitmap bitmap = new Bitmap(rect.Width, rect.Height);

        Graphics g = Graphics.FromImage(bitmap);

       // g.CopyFromScreen(sourcePoint, destinationPoint, rect.Size);

        g.CopyFromScreen(new Point(rect.Left, rect.Top), Point.Empty, rect.Size);

        bitmap.Save(filepath, ImageFormat.Bmp);


        //Console.WriteLine("(width, height) = ({0}, {1})", maxx - minx, maxy - miny);


    }


}

}

Roshan Vincent
  • 89
  • 1
  • 12
  • Where's your code that capture the screen area ? – Rohit Prakash Feb 24 '15 at 05:02
  • Unlike forum sites, we don't use "Thanks", or "Any help appreciated", or signatures on [so]. See "[Should 'Hi', 'thanks,' taglines, and salutations be removed from posts?](http://meta.stackexchange.com/questions/2950/should-hi-thanks-taglines-and-salutations-be-removed-from-posts). – John Saunders Feb 24 '15 at 05:03
  • Has it got something to do with the foreground and background window? – Roshan Vincent Feb 24 '15 at 05:29

1 Answers1

0
 Bitmap bmpScreenshot = new Bitmap(Screen.AllScreens[1].Bounds.Width, Screen.AllScreens[1].Bounds.Height, PixelFormat.Format32bppArgb);

            Graphics.FromImage(bmpScreenshot).CopyFromScreen(
                                         Screen.AllScreens[1].Bounds.X,
                                         Screen.AllScreens[1].Bounds.Y,
                                         0,
                                         0,
                                         Screen.AllScreens[1].Bounds.Size,
                                         CopyPixelOperation.SourceCopy);

            this.picExtendedModitorScreen.Image = bmpScreenshot;
            this.picExtendedModitorScreen.Refresh();

Put this code in timer tick event.

I have put extended screen 1 in the code you can change it to any other.

Dhaval
  • 62
  • 8