run application on a dual screen environment [duplicate]

落花浮王杯 提交于 2019-12-04 14:33:45

问题


Possible Duplicate:
How do I find what screen the application is running on in C#

Any ideas to check whether current application is run on primary screen or not in a dual screen environment? I am using VSTS 2008 + C# + .Net 3.5. I want to add code in my application to detect whether current application is run on primary screen or not.

thanks in advance, George


回答1:


You can use the Screen class which can tell you whether or not a control is on a particular screen or not. You can also get the primary monitory, and every Screen object also has a Primary property which indicates whether or not it is the primary monitory.

Here's the msdn article.

You should be able to use it like this:

var monitor = Screen.FromControl(this);

if (monitor.Primary) //the monitor returned is the primary monitor



回答2:


NOT TESTED: (don't have a dual screen setup at the moment to test on)

bool onPrimary = this.Bounds.IntersectsWith(Screen.PrimaryScreen.Bounds);

where "this" is the main form of your application.

EDIT: Just tested it, it works as expected.



来源:https://stackoverflow.com/questions/1039979/run-application-on-a-dual-screen-environment

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