views:

208

answers:

2

Hello everyone,

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  A: 

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.

BFree
+4  A: 

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
Joseph