Click here to Skip to main content
15,861,125 members
Please Sign up or sign in to vote.
4.00/5 (1 vote)
See more:
I know how to get the monitor dimensions, virtual monitor dimensions,
but how do I get the location of the second monitor in relationship to
the original?
On the desktop when I go into my property settings for the monitor I
can move around the monitors so if say the second monitor is lower
than the first I can position it accordingly. Is there some way to get those status values?
For instance I'd like to know if the secondary monitor is above,
below, to the right, or left of the primary monitor? Say if it's to
the right and not aligned perfectly I'd like to know what Y coordinate
it starts/ends at compared to the primary monitor.
Posted
Comments
Kim Togo 16-Jun-11 14:27pm    
Please see my updated Solution.

Check out Screen Class[^]

If you run this code:
C#
foreach (Screen screen in Screen.AllScreens)
{
  Console.WriteLine("Device Name: " + screen.DeviceName);
  Console.WriteLine("Bounds: " +
      screen.Bounds.ToString());
  Console.WriteLine("Type: " +
      screen.GetType().ToString());
  Console.WriteLine("Working Area: " +
      screen.WorkingArea.ToString());
  Console.WriteLine("Primary Screen: " +
      screen.Primary.ToString());
}


Then for my computer it returns:
Device Name: \\.\DISPLAY1
Bounds: {X=0,Y=0,Width=1920,Height=1080}
Type: System.Windows.Forms.Screen
Working Area: {X=0,Y=0,Width=1920,Height=1050}
Primary Screen: True

Device Name: \\.\DISPLAY2
Bounds: {X=1920,Y=0,Width=1920,Height=1080}
Type: System.Windows.Forms.Screen
Working Area: {X=1920,Y=0,Width=1920,Height=1080}
Primary Screen: False


If you look at Working Area, you can see the X and Y is different.
And there you can see it monitor is above, below, to the right, or left of the primary monitor.

My primary monitor is \\.\DISPLAY1 and to my right I have the secondary monitor.
 
Share this answer
 
v2
Comments
Kim Togo 16-Jun-11 14:21pm    
[From OP]
Already did that – tried every Property and Method in that class.
Sorry for the disappointment.

Any other suggestions?
Sergey Alexandrovich Kryukov 16-Jun-11 14:52pm    
Not clear what's missing.
This is a good answer, my 5.
--SA
FreshMax 21-Jun-11 2:08am    
The solution is great! - I didn't say it's not the answer to my question. I just thought there would be an easier way to get the location of the 2nd screen.

Thank you anyway for the great answer! :)
Kim Togo 21-Jun-11 2:20am    
You are welcome.
Your try like this,

C#
Screen[] sc;
           sc = Screen.AllScreens;
           //get all the screen width and heights
           if (sc.Length > 1)
           {
               customerdisplay.FormBorderStyle = FormBorderStyle.None;
               customerdisplay.Left = sc[1].Bounds.Width;
               customerdisplay.Top = sc[1].Bounds.Height;
               customerdisplay.StartPosition = FormStartPosition.Manual;
               customerdisplay.Location = sc[1].Bounds.Location;
               Point p = new Point(sc[1].Bounds.Location.X, sc[1].Bounds.Location.Y);
               customerdisplay.Location = p;
               customerdisplay.WindowState = FormWindowState.Maximized;
               customerdisplay.Show();
           }

customerdisplay is the form which you want to show in secondary monitor.

Hope be helpful,
Theingi Win
 
Share this answer
 
Comments
Kim Togo 17-Jun-11 1:58am    
Nice code sample. My 5.
Theingi Win 17-Jun-11 2:17am    
Thanks for your vote! KimTogo
i think you are asking about the resolution of monitor if i am right then you can do it by the help of Java script.
 
Share this answer
 
Comments
Kim Togo 16-Jun-11 14:29pm    
OP does not mention anything about Javascript.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900