Screen Coordinates of Secondary Screen

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

In a multi-monitor environment, a form I am creating at run time keeps
placing itself on the primary screen, even if the main form of the program
making the call is on the secondary screen.

How do I place a form on the secondary screen (monitor)?
 
Zorpiedoman,
I normally set the bounds of my form to the bounds of the secondary screen.

Something like (VB.NET):

Protected Overrides Sub OnLoad(ByVal e As System.EventArgs)
MyBase.OnLoad(e)
Dim s As Screen
For Each s In Screen.AllScreens
If Not s.Primary Then Exit For
Next
Me.Bounds = s.Bounds
Me.WindowState = FormWindowState.Maximized
End Sub

NOTE: I look for the non primary screen, rather then assume AllScreens[1] is
the second screen... The above code works if there is no secondary monitor
(it just uses the primary).


--
Hope this helps
Jay [MVP - Outlook]
..NET Application Architect, Enthusiast, & Evangelist
T.S. Bradley - http://www.tsbradley.net


| In a multi-monitor environment, a form I am creating at run time keeps
| placing itself on the primary screen, even if the main form of the program
| making the call is on the secondary screen.
|
| How do I place a form on the secondary screen (monitor)?
|
|
|
| --
| --Zorpie
 
Jay,
NOTE: I look for the non primary screen, rather then assume AllScreens[1] is
the second screen... The above code works if there is no secondary monitor
(it just uses the primary).

But it seems to assume that there is at most one secondary monitor,
what if you have more than that? If you have one form and want another
to appear on the same screen wouldn't it be better to do something
like

form2.Bounds = Screen.FromControl(form1).Bounds


Mattias
 
| But it seems to assume that there is at most one secondary monitor,
| what if you have more than that?
Yes my code is written to find the first secondary monitor.


| form2.Bounds = Screen.FromControl(form1).Bounds

Doh! I miss read the original question. Screen.FromControl would be better
to find the screen where a form is currently displayed.

--
Hope this helps
Jay [MVP - Outlook]
..NET Application Architect, Enthusiast, & Evangelist
T.S. Bradley - http://www.tsbradley.net


| Jay,
|
| >NOTE: I look for the non primary screen, rather then assume AllScreens[1]
is
| >the second screen... The above code works if there is no secondary
monitor
| >(it just uses the primary).
|
| But it seems to assume that there is at most one secondary monitor,
| what if you have more than that? If you have one form and want another
| to appear on the same screen wouldn't it be better to do something
| like
|
| form2.Bounds = Screen.FromControl(form1).Bounds
|
|
| Mattias
|
| --
| Mattias Sjögren [C# MVP] mattias @ mvps.org
| http://www.msjogren.net/dotnet/ | http://www.dotnetinterop.com
| Please reply only to the newsgroup.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top