Duplicate Windows form on multiple screen in c#

て烟熏妆下的殇ゞ 提交于 2019-12-03 16:48:05

One possible way to do it would be to capture the form that is inputting the data to a image on a timer (use a reasonable delay so that it's "almost realtime") and use it on a PictureBox on the secondary form. To capture the form to a image you do:

Bitmap bmp = new Bitmap(form.Width, form.Height);
form.DrawToBitmap(bmp, new Rectangle(Point.Empty, bmp.Size));

Then you assign bmp as the image to the PictureBox on the other form.

I've made a quick sample project and uploaded it here: https://www.dropbox.com/s/pjuk3zvpbglhodb/SOTestMirror.zip?dl=0

Lacks opening the form on the secondary screen and styling, but shows a possible way to do it

The result is:

For the record: I have no clue why when DrawToBitmap is called on a form it copies to the bitmap using a Windows 7 chrome instead of the Windows 8 one... that's interesting, to say the least (and I'd say a bug). That's running on Win 8.1. (Since I haven't seen this mentioned anywhere, I've opened a bug on Connect: https://connect.microsoft.com/VisualStudio/feedback/details/1059444/in-windows-8-drawtobitmap-on-a-form-draws-the-windows-7-chrome)

Here are simple code that take a screenshot from the extended screen and display in the picture box. you can save to image file as well.

Add this code in timer to refresh screen at some interval.

private Bitmap bmpScreenshot;
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);

pictureBox1.Image = bmpScreenshot;
pictureBox1.Refresh();
GC.Collect();

you also can get the screenshot of primary screen.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!