The bounds bit works... but it slams the window to full screen. I sure
could use some help offsetting the bounds.
I have been playing with saving the height, top and left, then trying to
dynamically resize the form on the secondary monitor as far as width
goes, but I somehow always end up with it full screen, here is the code
I have so far.
If oLUConfig.HasBeenConfigured Then
Me.Height = oLUConfig.IRHeight
Me.Width = oLUConfig.IRWidth
Me.Left = oLUConfig.IRLeft
Me.Top = oLUConfig.IRTop
If CheckForMultipleMonitors() AndAlso
(oLUConfig.IRScreenDeviceName <> "") Then
Dim s As Screen
Dim bFound As Boolean = False
Dim sName As String
For Each s In Screen.AllScreens
sName =oUtility.StripControlCharacters(s.DeviceName)
If sName = oLUConfig.IRScreenDeviceName Then
Me.SetDesktopBounds(Me.Left, Me.Top, Me.Width,
Me.Height)
bFound = True
me.bounds = s.bounds
me.setdesktopbounds(oluconfig.IRLeft, oluconfig.IRTop,
oluconfig.IRWidth, oluconfig.IRHeight)
Exit For
End If
Next
If Not bFound Then
Me.Bounds = Screen.PrimaryScreen.Bounds
End If
Else
Me.Bounds = Screen.PrimaryScreen.Bounds
End If
Else
Me.Height = 256
Me.Width = Screen.PrimaryScreen.WorkingArea.Width
Me.Top = iScreenHeight - Me.Height
Me.Left = Screen.PrimaryScreen.WorkingArea.Left
Me.SetDesktopBounds(Me.Left, Me.Top, Me.Width, Me.Height)
End If
Robert,
I normally set the bounds of the form to the bounds of the Screen (monitor)
that I want the form to appear on.
Something like:
Protected Overrides Sub OnLoad(ByVal e As System.EventArgs)
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
Will cause the form to appear "full screen" on the first secondary monitor
if one is present.
You should be able to use Rectangle.Location & Rectangle.Offset to adjust
the bounds before you set them if you don't want a "full screen" window.
Post if you need help with offsetting the bounds.
Hope this helps
Jay
| That was perfect! Worked for me... Many thanks! Now you would not happen
| to know how I can tell a form to appear, other than maximized, on a
| screen other than the primary display would you?
|
| Cheers,
|
| Bob Porter
|
| Jay B. Harlow [MVP - Outlook] wrote:
| > Robert,
| > It sounds like Screen.DeviceName contains an embedded and/or trailing
Null
| > Chars (ControlChars.NullChar).
| >
| > Remember that ControlChars.NullChar is a valid System.String character,
| > however most Win32 APIs, including the VS.NET debugger, treat it as a
string
| > terminator.
| >
| > I would use either String.Trim or String.SubString to remove the
trailing
| > ControlChars.NullChar.
| >
| > Dim s As Screen
| > Dim deviceName As String
| >
| > Dim length As Integer =
| > s.DeviceName.IndexOf(ControlChars.NullChar)
| > If length = -1 Then
| > deviceName = s.DeviceName
| > Else
| > deviceName = s.DeviceName.Substring(0, length)
| > End If
| >
| > Hope this helps
| > Jay
| >
| > | > |I have been experimenting with the Screen object. It has a property
| > | called Screen.DeviceName which returns a string value similar to the
| > | following:
| > |
| > | \\.\DISPLAY1 or \\.\DISPLAY2
| > |
| > | I have 2 questions. When I assign the value to a class property and
then
| > | serialize that class using a SoapFormatter I get a bunch of garbage
| > | characters after the name. Console.Writeline does not display these
| > | characters, but it does show a " in front of the string but not at the
| > end?
| > |
| > | Secondly, I want my application to remember which monitor it was
| > | displayed on, and in what location and size etc.
| > |
| > | I have the size handled okay, and using SetDesktopBounds I can get it
| > | back where it started, but cannot seem to figure out how to tell it
| > | which monitor to use?
| > |
| > | Any help would be appreciated.
| > |
| > | Cheers,
| > |
| > | Robert Porter
| >
| >