Duplicating windows form across multiple screens in c #

I am developing a feedback system for a car company. The billing counter has a setup with two monitors: one for the person conducting the payment and one for the customer who gives feedback. My need is to duplicate the Windows form on both screens as mirrored images so that the billing recipient can see what feedback the customer is giving.

I am using the following code to display on a secondary screen:

 Screen[] sc;
        Form f = new Form();
        sc = Screen.AllScreens;
        f.FormBorderStyle = FormBorderStyle.None;
        f.Left = sc[1].Bounds.Left;
        f.Top = sc[1].Bounds.Top;
        f.Height = sc[1].Bounds.Height;
        f.Width = sc[1].Bounds.Width;
        f.StartPosition = FormStartPosition.Manual;
        f.Show();

      

However, it will not reflect the shape on the main screen. I also mentioned the duplicate window question , but it will create different instances for the same form, which will not reflect the Windows form. How can I mirror it on both screens?

+3


source to share


2 answers


One possible way to do this is to capture a form that timer-injects data into the image (use a reasonable delay so that it is "near real-time") and uses it on PictureBox

a secondary form. To write the form to the image you make:

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

      

Then you designate bmp

as an image PictureBox

in a different shape.

I made a quick example project and downloaded it here: https://www.dropbox.com/s/pjuk3zvpbglhodb/SOTestMirror.zip?dl=0



Can't open form on secondary screen and styling, but shows a possible way to do it

Result: Result

For the record: I don't know why, when DrawToBitmap

called on a form, it copies to a bitmap using Windows 7 chrome instead of Windows 8, one of which is interesting, if not less (and I'll say a bug). This works on Win 8.1. (Since I haven't seen this anywhere, I ran into a bug on Connect: https://connect.microsoft.com/VisualStudio/feedback/details/1059444/in-windows-8-drawtobitmap-on-a-form-draws-the -windows-7-chrome )

+4


source


Here is a simple code that takes a screenshot from the extended screen and displays in the image window. you can also save the image file.

Add this code to the timer to refresh the screen at a certain 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 can also get a screenshot of the main screen.

0


source







All Articles