MS12.02.2016
This commit is contained in:
@@ -4,8 +4,15 @@ Imports System.IO
|
||||
Public Class ClassWindowLocation
|
||||
Public Shared Sub LoadFormLocationSize(ByRef form As Form)
|
||||
Try
|
||||
Dim _path As String
|
||||
_path = Path.Combine(Application.UserAppDataPath(), "frm" & form.Name & "-Layout.xml")
|
||||
Dim _path, _pathold As String
|
||||
|
||||
_path = Path.Combine(Application.UserAppDataPath(), form.Name & "-Layout.xml")
|
||||
_pathold = _path.Replace("frm", "frmfrm")
|
||||
If File.Exists(_pathold) Then
|
||||
Dim newfilename = Path.GetFileName(_path)
|
||||
My.Computer.FileSystem.RenameFile(_pathold, newfilename)
|
||||
_path = Path.Combine(Application.UserAppDataPath(), form.Name & "-Layout.xml")
|
||||
End If
|
||||
Dim layout As ClassLayout = New ClassLayout(_path)
|
||||
Dim settings As System.Collections.Generic.List(Of ClassSetting)
|
||||
settings = layout.Load()
|
||||
@@ -36,13 +43,19 @@ Public Class ClassWindowLocation
|
||||
If x = 5000 Then
|
||||
form.WindowState = FormWindowState.Maximized
|
||||
Else
|
||||
If x >= 0 And y >= 0 Then
|
||||
form.Location = New Point(x, y)
|
||||
End If
|
||||
If w > 0 And h > 0 Then
|
||||
form.Size = New Size(w, h)
|
||||
|
||||
Dim rect As New Rectangle(x, y, 0, 0)
|
||||
If IsVisibleOnAnyScreen(rect) Then
|
||||
If x >= 0 And y >= 0 Then
|
||||
form.Location = New Point(x, y)
|
||||
End If
|
||||
If w > 0 And h > 0 Then
|
||||
form.Size = New Size(w, h)
|
||||
End If
|
||||
End If
|
||||
|
||||
|
||||
|
||||
End If
|
||||
Catch notFoundEx As System.IO.FileNotFoundException
|
||||
|
||||
@@ -50,12 +63,29 @@ Public Class ClassWindowLocation
|
||||
MsgBox("Error while loading Window Position!" & vbNewLine & ex.Message, MsgBoxStyle.Critical)
|
||||
End Try
|
||||
End Sub
|
||||
|
||||
Private Shared Function IsVisibleOnAnyScreen(rect As Rectangle)
|
||||
Try
|
||||
Dim result As Boolean = False
|
||||
For Each Screen As Screen In Screen.AllScreens
|
||||
If Screen.WorkingArea.IntersectsWith(rect) Then
|
||||
result = True
|
||||
End If
|
||||
Next
|
||||
If result = False Then
|
||||
ClassLogger.Add(">> Saved layout is not fitting to Resolution. Default is loaded.", True)
|
||||
End If
|
||||
Return result
|
||||
Catch ex As Exception
|
||||
ClassLogger.Add("Error in IsVisibleOnAnyScreen: " & ex.Message, True)
|
||||
Return False
|
||||
End Try
|
||||
End Function
|
||||
|
||||
|
||||
Public Shared Sub SaveFormLocationSize(ByRef form As Form)
|
||||
Try
|
||||
Dim _path As String
|
||||
_path = Path.Combine(Application.UserAppDataPath(), "frm" & form.Name & "-Layout.xml")
|
||||
_path = Path.Combine(Application.UserAppDataPath(), form.Name & "-Layout.xml")
|
||||
|
||||
Dim layout As ClassLayout = New ClassLayout(_path)
|
||||
Dim settings As System.Collections.Generic.List(Of ClassSetting) = New System.Collections.Generic.List(Of ClassSetting)
|
||||
|
||||
Reference in New Issue
Block a user