Roland-2 icon

iniFormForceInbounds

Roland-2 | PRO | 03/03/17 10:21:00 AM UTC | 0 ⭐ | 234 👁️ | Never ⏰ | []
VB.NET |

3.91 KB

|

None

|

0 👍

/

0 👎

Region "Public Properties"
 
    Public Property WindowTop() As Double
        Get
            Return _windowTop
        End Get
        Set(ByVal value As Double)
            _windowTop = value
        End Set
    End Property
 
    Public Property WindowLeft() As Double
        Get
            Return _windowLeft
        End Get
        Set(ByVal value As Double)
            _windowLeft = value
        End Set
    End Property
 
    Public Property WindowHeight() As Double
        Get
            Return _windowHeight
        End Get
        Set(ByVal value As Double)
            _windowHeight = value
        End Set
    End Property
 
    Public Property WindowWidth() As Double
        Get
            Return _windowWidth
        End Get
        Set(ByVal value As Double)
            _windowWidth = value
        End Set
    End Property
 
 
    Private _tempstring As String
    Public Property initempstring() As String
        Get
            Return _tempstring
        End Get
        Set(ByVal value As String)
            _tempstring = value
        End Set
    End Property
 
 
    Public Property WindowState() As System.Windows.Forms.FormWindowState
        Get
            Return _windowState
        End Get
        Set(ByVal value As System.Windows.Forms.FormWindowState)
            _windowState = value
        End Set
    End Property
 
#End Region 'Public Properties
 
    Public Sub Save()
        If Not Form1.WindowState = 1 Then
            WriteInteger("windowTop", "top", _windowTop)
            WriteInteger("windowLeft", "left", _windowLeft)
 
 
            WriteInteger("WindowHeight", "height", _windowHeight)
            WriteInteger("WindowWidth", "width", _windowWidth)
        End If
 
    End Sub
    Public Sub Load()
        Dim temptop As Integer = GetInteger("windowTop", "top", "0")
        If temptop > 0 Then
            _windowTop = temptop
        Else
            _windowTop = 0
        End If
        Dim templeft As Integer = GetInteger("windowLeft", "left", "0")
        If templeft > 0 Then
            _windowLeft = templeft
        Else
            _windowLeft = 0
        End If
        Form1.Location = New Point(WindowLeft, WindowTop)
 
        _windowHeight = GetInteger("WindowHeight", "height", "0")
        _windowWidth = GetInteger("WindowWidth", "width", "0")
 
 
        If (WindowWidth + templeft) < Screen.PrimaryScreen.WorkingArea.Width AndAlso (WindowHeight + temptop) < Screen.PrimaryScreen.WorkingArea.Height Then
            form1.Height = WindowHeight
            form1.Width = WindowWidth
        Else
            If (WindowWidth) < Screen.PrimaryScreen.WorkingArea.Width AndAlso (WindowHeight) < Screen.PrimaryScreen.WorkingArea.Height Then
                Dim centrex As Double = (Screen.PrimaryScreen.WorkingArea.Width - WindowWidth) / 2
                Dim centrey As Double = (Screen.PrimaryScreen.WorkingArea.Height - WindowHeight) / 2
                form1.Height = WindowHeight
                form1.Width = WindowWidth
                form1.Location = New Point(centrex, centrey)
            Else
                form1.Location = New Point(5, 5)
                SubResize(form1, 95, 95)
            End If
        End If
 
 
    End Sub
 
    Public Shared Sub SubResize(ByVal F As Form, ByVal percentW As Single, ByVal percentH As Single)
        Dim FormHeight As Long
        Dim FormWidth As Long
 
        'Calculate the new height and width the form needs to be resized to, based on the current avaible screen area.
        FormHeight = Int((Screen.PrimaryScreen.WorkingArea.Height) * (percentH / 100))
        FormWidth = Int((Screen.PrimaryScreen.WorkingArea.Width) * (percentW / 100))
 
        'Use the Form that is to be resized.
        With F
            'Change the demensions and position of the form.
            .Height = FormHeight
            .Width = FormWidth
        End With
 
    End Sub

Comments