Base: Add ScreenEx
This commit is contained in:
parent
76cba215fe
commit
00cff028c9
@ -57,6 +57,7 @@
|
||||
<Reference Include="System.Runtime.Serialization" />
|
||||
<Reference Include="System.ServiceModel" />
|
||||
<Reference Include="System.Transactions" />
|
||||
<Reference Include="System.Windows.Forms" />
|
||||
<Reference Include="System.Xml" />
|
||||
<Reference Include="System.Core" />
|
||||
<Reference Include="System.Xml.Linq" />
|
||||
@ -99,6 +100,7 @@
|
||||
<DesignTimeSharedInput>True</DesignTimeSharedInput>
|
||||
</Compile>
|
||||
<Compile Include="PerformanceEx.vb" />
|
||||
<Compile Include="ScreenEx.vb" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<EmbeddedResource Include="My Project\Resources.resx">
|
||||
|
||||
48
Base/ScreenEx.vb
Normal file
48
Base/ScreenEx.vb
Normal file
@ -0,0 +1,48 @@
|
||||
Imports System
|
||||
Imports System.Drawing
|
||||
Imports System.Windows.Forms
|
||||
|
||||
Public Class ScreenEx
|
||||
Public Shared Function GetLocationWithinScreen(pLocation As Point) As Point?
|
||||
For Each screen As Screen In Screen.AllScreens
|
||||
If screen.Bounds.Contains(pLocation) Then
|
||||
Return New Point(pLocation.X - screen.Bounds.Left, pLocation.Y - screen.Bounds.Top)
|
||||
End If
|
||||
Next
|
||||
|
||||
Return Nothing
|
||||
End Function
|
||||
|
||||
Public Shared Sub RestoreFormPosition(pForm As Form, pPosition As Point)
|
||||
Dim oLocationWithinScreen As Point? = GetLocationWithinScreen(pPosition)
|
||||
|
||||
If oLocationWithinScreen Is Nothing Then
|
||||
Dim oPrimaryScreen = Screen.PrimaryScreen
|
||||
pForm.StartPosition = FormStartPosition.CenterScreen
|
||||
Else
|
||||
pForm.StartPosition = FormStartPosition.Manual
|
||||
pForm.Location = pPosition
|
||||
End If
|
||||
End Sub
|
||||
|
||||
Public Shared Sub RestoreFormState(pForm As Form, pFormState As FormWindowState)
|
||||
If pFormState = FormWindowState.Maximized Then
|
||||
pForm.WindowState = FormWindowState.Normal
|
||||
pForm.WindowState = FormWindowState.Maximized
|
||||
ElseIf pFormState = FormWindowState.Minimized Then
|
||||
pForm.WindowState = FormWindowState.Normal
|
||||
pForm.WindowState = FormWindowState.Minimized
|
||||
Else
|
||||
pForm.WindowState = FormWindowState.Normal
|
||||
End If
|
||||
End Sub
|
||||
|
||||
Public Shared Sub RestoreFormState(pForm As Form, pFormState As String)
|
||||
Dim oFormState As FormWindowState
|
||||
If Not [Enum].TryParse(pFormState, oFormState) Then
|
||||
oFormState = FormWindowState.Normal
|
||||
End If
|
||||
|
||||
RestoreFormState(pForm, oFormState)
|
||||
End Sub
|
||||
End Class
|
||||
Loading…
x
Reference in New Issue
Block a user