在C#中的多个屏幕上重复Windows窗体

编程入门 行业动态 更新时间:2024-10-12 01:26:21
本文介绍了在C#中的多个屏幕上重复Windows窗体的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我正在为一家汽车公司开发反馈系统.在计费台上,有一个双显示器设置:一个用于计费人,一个用于提供反馈的客户.我需要在两个屏幕上都将Windows窗体复制为镜像,以便帐单人员可以看到客户给出的反馈.

I am developing a feedback system for an automotive company. On the billing desk, there is a dual monitor setup: one for a billing person and one for a customer who's giving feedback. My need is to duplicate a Windows form on both screens, as mirror images, So that the billing person can see what feedback the customer is giving.

我正在使用以下代码在辅助屏幕上显示:

I am using the code below for display on the 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();

但是,它不会在主屏幕上反映该表单.我还提到了重复窗口问题,但是它将创建不同的实例对于相同的表单,它不会镜像Windows表单.如何在两个屏幕上进行镜像?

However, it will not mirror the form on the primary screen. I had also referred to the duplicate window question, but it will create different instances for the same form, which will not mirror the Windows form. How can I mirror it on both screens?

推荐答案

一种可行的方法是捕获在计时器上将数据输入到图像的表单(使用合理的延迟,以便几乎实时"),并在辅助表格的PictureBox上使用它.要将表单捕获为图像,您可以执行以下操作:

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

然后将bmp作为图像分配给另一种形式的PictureBox.

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

我制作了一个快速示例项目,并将其上传到此处: www.dropbox/s/pjuk3zvpbglhodb/SOTestMirror.zip?dl=0

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

缺少在辅助屏幕上打开表单和样式的功能,但显示了一种可行的方法

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

结果是:

作为记录:我不知道为什么在窗体上调用DrawToBitmap时会使用Windows 7 chrome而不是Windows 8 chrome复制到位图的原因……至少,这很有趣(而且我会说一个错误).那是在Win 8.1上运行的. (由于我从未在任何地方看到此内容,因此我在Connect上打开了一个错误:"> connect.microsoft/VisualStudio/feedback/details/1059444/in-windows-8-drawtobitmap- on-a-form-draws-the-windows-7-chrome )

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: connect.microsoft/VisualStudio/feedback/details/1059444/in-windows-8-drawtobitmap-on-a-form-draws-the-windows-7-chrome)

更多推荐

在C#中的多个屏幕上重复Windows窗体

本文发布于:2023-10-08 01:10:07,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1471067.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:多个   窗体   屏幕上   Windows

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!