\\.\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
First, I suggest you assign the DeviceName to a string first, and note the
length to see if it has redundant character, and then serialize the string
value direct to see if the problem persists.
Based on my test, it is shown correct in messagebox.
Second, for the monitor issue, I think we may use the DesktopLocation
property to set a position large than first desktop.
e.g. the first desktop is 1024*768, then we can set the DesktopLocation to
1100,100, then it will show on the second monitor.
Best regards,
Peter Huang
Microsoft Online Partner Support
Get Secure! - www.microsoft.com/security
This posting is provided "AS IS" with no warranties, and confers no rights.
I did assign the value to a string property first, and in MsgBox it
displays correctly. When serialized using the SoapFormatter it is when
it seems to acquire the extra garbage characters.
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
"Robert Porter" <rhys...@noemail.nospam> wrote in message
news:e%237ErQ%23aFH...@TK2MSFTNGP10.phx.gbl...
Cheers,
Bob Porter
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
"Robert Porter" <rhys...@noemail.nospam> wrote in message
news:O9CMUnE...@TK2MSFTNGP12.phx.gbl...
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
Seeing as you have a position in mind, I would simply set the Form.Location
to the Saved.Location + Screen.Bounds.Location.
Something like:
Protected Overrides Sub OnLoad(ByVal e As EventArgs)
MyBase.OnLoad(e)
Dim secondaryScreen As Screen
' look up the secondaryScreen
For Each secondaryScreen In Screen.AllScreens
If Not secondaryScreen.Primary Then Exit For
Next
' Use the primary screen if there is no secondary screen
If secondaryScreen Is Nothing Then secondaryScreen =
Screen.PrimaryScreen
' Move the form to the secondary screen
' use the forms current location
Dim location As Point = Me.Location
' or you could use the saved location
Dim location As New Point(oLUConfig.IRLeft, oLUConfig.IRTop)
location.Offset(secondaryScreen.Bounds.X, secondaryScreen.Bounds.Y)
Me.Location = location
' Assumes the size is already set...
End Sub
Hope this helps
Jay
"Robert Porter" <rhys...@noemail.nospam> wrote in message
news:e0wtfJFb...@tk2msftngp13.phx.gbl...
Cheers,
Bob
Thanks for you Jay's elegant contribution in the community.
All will benefit from your suggestion. :)