屏幕捕获我的应用程序中没有捕获对话框

本文关键字:对话框 应用程序 我的 屏幕 | 更新日期: 2024-07-27 09:02:24

我有一个用WPF和WinForms制作的应用程序A。我用WinForms编写了另一个用于捕获屏幕的应用程序。我面临的问题是,应用程序A中出现的对话框没有在屏幕中捕获。整个屏幕都会被捕获,包括对话框后面的区域,但对话框不会被捕获。

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

    }

}

}

屏幕捕获我的应用程序中没有捕获对话框

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

将此代码放入计时器刻度事件中。

我已经在代码中放入了扩展屏幕1,您可以将其更改为任何其他屏幕。