如何在多显示器系统上弹出消息框到特定屏幕 [英] How to pop up messagebox to particular screen on multi-display system

查看:195
本文介绍了如何在多显示器系统上弹出消息框到特定屏幕的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

您好,



我的PC上有多显示器设置,我想在特定应用程序窗口所在的特定显示器上弹出一个消息框,即如果应用程序A在屏幕#2上运行,则消息框应出现在屏幕#2上。



如何在C#上执行此操作?谢谢



我尝试了什么:



我还没有尝试过任何东西但是,需要一些帮助

Hello,

I have multi-display setup on my PC, I want to pop up a messagebox onto particular monitor where the particular application window is located, i.e. if application A is running on screen #2, the messagebox should be appeared on screen #2.

How can I do it on C#? Thanks

What I have tried:

I have not try anything yet, need some help

推荐答案

可能你的意思是使用在不同的监视器上呈现的虚拟统一桌面。这是在Windows中使用多个监视器的标准模式之一。你没有清楚地解释你正在使用什么模式,但我认为这是Windows上唯一可以同时与你的问题相关的模式。



所以,如果这是我的想法,解决方案将不使用 MessageBox ,因为没有办法明确设置其屏幕或坐标。相反,您需要使用自己的表单或窗口并显式计算所需位置(顶部位置)。您将需要实现您通常期望从消息框中获得的行为,或者更多。



这是事情:所有屏幕使用相同的联合坐标系统;如果你指定这个屏幕的坐标,你会在另一个屏幕上显示一些东西(并添加一些偏移,可能取决于屏幕大小和窗口大小)。



一种方式找到所有屏幕的坐标是这样的:

https://msdn.microsoft.com/en-us/library/system.windows.forms.screen.allscreens%28v=vs.110%29.aspx [< a href =https://msdn.microsoft.com/en-us/library/system.windows.forms.screen.allscreens%28v=vs.110%29.aspx\"target =_ blanktitle =新窗口> ^ ],

屏幕类(System.Windows.Forms) [ ^ ],

卵石n.GetBounds方法(Point)(System.Windows.Forms) [ ^ ],

Screen.GetBounds方法(矩形)(System.Windows.Forms) [ ^ ]。



不幸的是,你没有指定您正在使用的UI框架/库。你可以使用 System.Windows.Forms 立即使用这个解决方案,但原则上你甚至可以在WPF中使用这种技术,但是要注意这个问题(这实际上是可以解决的):桌面 - 是否有WPF等效于System.Windows.Forms.Screen? - 堆栈溢出 [ ^ ]。



参见:

SystemParameters.VirtualScreenHeight Property(System.Windows) [ ^ ],

WPF教程查询屏幕分辨率 [ ^ ]。



如果您正在使用其他产品,请澄清。下次,请始终指定您正在使用的内容。



-SA
Probably you mean using the virtually unified desktop rendered on separate monitors. This is one of the standard modes of using multiple monitors in Windows. You did not clearly explain what mode you are using, but I think this is the only one available on Windows and relevant to your question at the same time.

So, if this is what I think, the solution would be not using MessageBox, because there is no a way to explicitly set its screen or coordinates. Instead, you need to use your own form or window and explicitly calculate required location (Left, Top or Location). You will need to implement the behavior you normally expect from a message box, or more than that.

Here is the thing: all the screens use the same united coordinates system; you show something on another screen if you specify the coordinates of this screen (and add some offset, possibly depending on the screen size and windows size).

One way of finding the coordinates of all screens is this:
https://msdn.microsoft.com/en-us/library/system.windows.forms.screen.allscreens%28v=vs.110%29.aspx[^],
Screen Class (System.Windows.Forms)[^],
Screen.GetBounds Method (Point) (System.Windows.Forms)[^],
Screen.GetBounds Method (Rectangle) (System.Windows.Forms)[^].

Unfortunately, you did not specify what UI framework/library you are using. You can use this solution immediately of you use System.Windows.Forms, but, in principle, you can use this technique even in WPF, but then be aware of the problem (which is actually solvable): desktop — Is there a WPF equaivalent to System.Windows.Forms.Screen? — Stack Overflow[^].

See also:
SystemParameters.VirtualScreenHeight Property (System.Windows)[^],
WPF Tutorial | Query Screen Resolutions[^].

If you are using something else, please clarity. Next time, always specify what you are using.

—SA


我正在写程序来控制我的AV接收器,所以我可以使用任何类型的框架。此时我正在使用添加了Windows.Forms参考的控制台应用程序。首先,它需要确定应用程序A正在运行哪个监视器,然后在该屏幕上弹出MessageBox。



感谢您的回复,我将花些时间学习您发布的链接。
I am writing the program to control my AV receiver so I can use any type of framework. At this moment I am working on console application with added Windows.Forms reference. First it needs to determine which monitor the application A is running and then pop up the MessageBox on that screen.

Thanks for your reply, I will take some time to study the link you posted.


这篇关于如何在多显示器系统上弹出消息框到特定屏幕的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆