如何确保表单显示在“附加”页面上在双显示器场景中进行显示器?
我有一个应用程序,其中有一个我想在第二个屏幕上显示的表单。
意思是如果应用程序在屏幕 A 上运行,当我单击菜单显示表单时,它应该显示在屏幕 B 上 如果应用程序在屏幕 B 上运行,并且当我单击菜单显示表单时,它应该显示在屏幕 A 上。
I have an application in which there is a form which I want to show on second screen.
Mean If application is running on screen A and when I click on menu to show Form it should display on Screen B
and same with if application is running on screen B and when I click on menu to show Form it should display on Screen A.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
您需要使用
屏幕
类来查找原始表单不在的屏幕,然后根据该屏幕的Bounds
设置第二个表单的Location
属性。例如:
这适用于任意数量的屏幕。
请注意,显卡可能会被配置为使 Windows 看到一个大屏幕而不是两个较小的屏幕,在这种情况下,这会变得更加困难。
You need to use the
Screen
class to find a screen that the original form is not on, then set the second form'sLocation
property based on that screen'sBounds
.For example:
This will work for any number of screens.
Note that it is possible that the video card is configured so that Windows sees one large screen instead of two smaller ones, in which case this becomes much more difficult.
下面的函数允许您在任何监视器上显示表单。对于您当前的场景,您可以调用此
showOnMonitor(1);
。本质上,您必须从
Screen.AllScreens
获取屏幕信息,然后获取每个屏幕的尺寸,然后将表单放置在您需要的位置注意不要忘记进行验证以确保您实际上有两个屏幕等否则访问
sc[showOnMonitor]
将会抛出异常Below is a function allowing you to display a form on any monitor. For your current scenario you can call this
showOnMonitor(1);
.Essentially you have to get screen information from
Screen.AllScreens
and then get the dimensions of each, then place your form where you need itNote don't forget to do validation to ensure you actually have two screens etc else an exception will be thrown for accessing
sc[showOnMonitor]
在 OnLoad 方法中更改窗口的位置。
On the OnLoad method change the Location of the window.
我将其用于 XNA 4 双屏应用程序(全屏 XNA 游戏窗口 + WinForm)
在 Form_Load() 方法中,放置以下代码:
I used this for an XNA 4 Dual Screen Application (Full Screen XNA Game Window + WinForm)
In the Form_Load() method, place the following code: