Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

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);


    }


}

}

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
249 views
Welcome To Ask or Share your Answers For Others

1 Answer

 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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...