Arranging window screens on multi-monitor Desktop

B

Bill Nguyen

This has been posted before but received no response:

I need to arrange window screens on the total area of a mulitple-mopnitor
desktop.
As an example, below is the bound info for my 2-monitor PC:

Device Name: \\.\DISPLAY1
Bounds: {X=1152,Y=0,Width=1152,Height=864}
Primary Screen: False

Device Name: \\.\DISPLAY2
Bounds: {X=0,Y=0,Width=1152,Height=864}
Primary Screen: True


Now I need to display a form on Display1 and another form on Display2
I don't know if this is possible using .NET or not.

Any help is greatly appreciated.

Bill
 
B

Bill Nguyen

Michel;
I already looked into it, and as a matter of fact, used AllScreens to
retrieve the screens info.
The problem is that I can't assign a form to a particular screen. I looked
into all the methods but do not know which one I shoudl use to display an
object to a screen. In short, I need an example of how to do this if it's
possible.

Thanks again

Bill
 
S

ShaneO

Bill said:
This has been posted before but received no response:

I need to arrange window screens on the total area of a mulitple-mopnitor
desktop.
As an example, below is the bound info for my 2-monitor PC:

Device Name: \\.\DISPLAY1
Bounds: {X=1152,Y=0,Width=1152,Height=864}
Primary Screen: False

Device Name: \\.\DISPLAY2
Bounds: {X=0,Y=0,Width=1152,Height=864}
Primary Screen: True


Now I need to display a form on Display1 and another form on Display2
I don't know if this is possible using .NET or not.

Any help is greatly appreciated.

Bill
Bill,

I understand your problem as I have 4 screens, however, the only way
I've ever solved it was by assigning Global Variables to hold screen
information and then referencing that information from other Forms.

Basically, I have the following in a Global Module -

Public Scrn() As Screen
Public gliPrimaryScreen, gliDesignatedScreen As UInt16

In my Main (Startup) Form I have -

Scrn = Screen.AllScreens

Dim X As UInt16
For Each S As Screen In Scrn
If S.Primary Then
gliPrimaryScreen = X
Exit For
End If
X += 1
Next

At this point I know the "Primary" Screen index value (can't always be
assumed to be "0").

I can then iterate through the other indexes to determine the layout of
the entire display area, and what order they're in.

Now, if I want to display a Form on a particular display I simply set
the "gliDesignatedScreen" variable prior to opening the Form and in that
Form's Load Event I use something like the following -

Private Sub SecondFrm_Load(ByVal sender As Object, ByVal e As
System.EventArgs) Handles Me.Load

Dim recScreenWorkingArea As Rectangle
Try
recScreenWorkingArea = Scrn(gliDesignatedScreen).WorkingArea
Catch ex As Exception
recScreenWorkingArea = Screen.PrimaryScreen.WorkingArea
End Try

End Sub

Now I can position/manipulate the Form based on the Bounds values
associated with the recScreenWorkingArea values.

There are probably easier ways to do all of this, but like you, I
haven't found them.

This approach was a quick and dirty method I used for a single
application that I needed for my own use and is in need of cleaning up,
but it does work!

I hope this helps. If you find something better I'd be interested to
hear about it.

ShaneO

There are 10 kinds of people - Those who understand Binary and those who
don't.
 
B

Bill Nguyen

Shane;
I tried but finally got lost!

Below is a simplified version of the routine I used to display multiple
windows on a desktop. The last part is where I tried to send the new window
to a different "Bound" but it never worked!

Any suggestion is greatly appreciated.

Bill



Private Sub loadMaps(ByVal dV As DataView, ByVal mMonitor As Integer)
Dim mdVR As DataRowView
dV.RowFilter = "monitorID = " & mMonitor
If dV.Count <= 0 Then
' MsgBox("No records found")
Exit Sub
End If

Dim mUrl, mMPPath As String ' mScreen, mUrl2, mUrl3, mUrl4 As String
Dim mScreenName, mvehicleID, mButtonName, mButtonText As String
Dim mModulus As Integer

Dim mPanel As New TableLayoutPanel
Dim mWeb, mWeb1, mWeb2, mWeb3, mWeb4 As New WebBrowser

Dim mButton, mButton1, mButton2, mButton3, mButton4 As Button




With mPanel

.ColumnCount = 2
.ColumnStyles.Add(New
System.Windows.Forms.ColumnStyle(System.Windows.Forms.SizeType.Percent,
50.0!))
.ColumnStyles.Add(New
System.Windows.Forms.ColumnStyle(System.Windows.Forms.SizeType.Percent,
50.0!))

.RowCount = 2
.RowStyles.Add(New
System.Windows.Forms.RowStyle(System.Windows.Forms.SizeType.Percent, 50.0!))
.RowStyles.Add(New
System.Windows.Forms.RowStyle(System.Windows.Forms.SizeType.Percent, 50.0!))

For Each mdVR In dV



mScreenName = mdVR.Item("panelID").ToString.Trim
mvehicleID = mdVR.Item("vehicleID").ToString.Trim
mUrl = "http://masterserver/" & mdVR.Item("mapPath1").Trim
mMPPath = mdVR.Item("mapPath2").ToString

mModulus = mdVR.Item("panelID") - ((mMonitor - 1) * 4)
mButtonName = mdVR.Item("mapPath2").ToString.Trim
mButtonText = "View GPS trail for vehicle " & mvehicleID & "
in Mappoint"


Select Case mModulus
Case 1

With mWeb1

.Dock = DockStyle.Fill

.Navigate(mUrl)

End With
.Controls.Add(mWeb1, 0, 0)


Case 2
With mWeb2

.Dock = DockStyle.Fill
.Navigate(mUrl)

End With
.Controls.Add(mWeb2, 1, 0)

Case 3
With mWeb3

.Dock = DockStyle.Fill
.Navigate(mUrl)

End With
.Controls.Add(mWeb3, 0, 1)
Case 4

With mWeb4

.Dock = DockStyle.Fill
.Navigate(mUrl)


End With
.Controls.Add(mWeb4, 1, 1)
Case Else


End Select

.Dock = DockStyle.Fill


Next




End With




Dim thisX, thisY, thisW, thisH As Integer
thisY = 0
thisW = 1152
thisH = 864
thisX = 1152 * (mMonitor - 1)
' MsgBox(thisX & " - " & thisY)
' Dim frmScreen As New frmMultiScreens
Dim frmScreen As New frmBlank
With frmScreen
.Text = "WF Truck Breadcumbs Display"
' .SetBounds(thisX, thisY, thisW, thisH)
'.SetDesktopBounds(thisX, thisY, thisW, thisH)
.Controls.Add(mPanel)
.WindowState = FormWindowState.Maximized
' .SetDisplayRectLocation(thisX, thisY)

.Show()
'.ShowDialog()
End With

'Me.Controls.Add(mPanel)
'Me.WindowState = FormWindowState.Maximized

End Sub
 
S

ShaneO

Bill said:
Shane;
I tried but finally got lost!
Bill, what you've posted seems way too much for what you're trying to
achieve!

If you take another look at the code I posted you'll see that "Scrn"
ends up as a Screen Object Array that holds everything you need.

As you only have 2 displays, once you use the code that sets the
"gliPrimaryScreen" variable then, in your case, you'll automatically
know which Scrn Array Index holds the details of your other display.

To use this information, just set "gliDesignatedScreen" value (either 0
or 1 in your case for Primary or Secondary) and Load your next Form.

In that Forms Load Event use the code I provided. Here's a full example
(watch for wrapping!) -

Dim recScreenWorkingArea As Rectangle
Try
recScreenWorkingArea = Scrn(gliDesignatedScreen).WorkingArea
Catch ex As Exception
recScreenWorkingArea = Screen.PrimaryScreen.WorkingArea
End Try

Dim CentreScreen As New Point
CentreScreen.X = (recScreenWorkingArea.Width / 2) +
(Scrn(gliDesignatedScreen).WorkingArea.Left) - (Me.Width / 2)
CentreScreen.Y = (recScreenWorkingArea.Height / 2) - (Me.Height / 2)
Me.Location = CentreScreen


Set "gliDesignatedScreen" to 0 or 1 and you'll see what happens. Try it
and let me know if you need any further assistance.

ShaneO

There are 10 kinds of people - Those who understand Binary and those who
don't.
 
J

Jay B. Harlow

Bill,
I have one form where I 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).

If you know the name of the screen you should be able to just use that to
"index" into the Screens collection.

Something like:

SetScreen("\\.\DISPLAY1")

Private Sub SetScreen(ByVal deviceName As String)
For Each s As Screen In Screen.AllScreens
If String.Equals(s.DeviceName, deviceName,
StringComparison.OrdinalIgnoreCase) Then
Me.Bounds = s.Bounds
Return
End If
Next
End Sub

If you have a "monitor" index, you should be able to simply index into the
array:

SetScreen(0)

Private Sub SetScreen(ByVal index As Integer)
Dim s As Screen = Screen.AllScreens(index)
Me.Bounds = s.Bounds
End Sub
 

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

Top