Advertisement
Roland-2

iniFormForceInbounds

Mar 3rd, 2017
85
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
VB.NET 3.91 KB | None | 0 0
  1. Region "Public Properties"
  2.  
  3.     Public Property WindowTop() As Double
  4.         Get
  5.             Return _windowTop
  6.         End Get
  7.         Set(ByVal value As Double)
  8.             _windowTop = value
  9.         End Set
  10.     End Property
  11.  
  12.     Public Property WindowLeft() As Double
  13.         Get
  14.             Return _windowLeft
  15.         End Get
  16.         Set(ByVal value As Double)
  17.             _windowLeft = value
  18.         End Set
  19.     End Property
  20.  
  21.     Public Property WindowHeight() As Double
  22.         Get
  23.             Return _windowHeight
  24.         End Get
  25.         Set(ByVal value As Double)
  26.             _windowHeight = value
  27.         End Set
  28.     End Property
  29.  
  30.     Public Property WindowWidth() As Double
  31.         Get
  32.             Return _windowWidth
  33.         End Get
  34.         Set(ByVal value As Double)
  35.             _windowWidth = value
  36.         End Set
  37.     End Property
  38.  
  39.  
  40.     Private _tempstring As String
  41.     Public Property initempstring() As String
  42.         Get
  43.             Return _tempstring
  44.         End Get
  45.         Set(ByVal value As String)
  46.             _tempstring = value
  47.         End Set
  48.     End Property
  49.  
  50.  
  51.     Public Property WindowState() As System.Windows.Forms.FormWindowState
  52.         Get
  53.             Return _windowState
  54.         End Get
  55.         Set(ByVal value As System.Windows.Forms.FormWindowState)
  56.             _windowState = value
  57.         End Set
  58.     End Property
  59.  
  60. #End Region 'Public Properties
  61.  
  62.     Public Sub Save()
  63.         If Not Form1.WindowState = 1 Then
  64.             WriteInteger("windowTop", "top", _windowTop)
  65.             WriteInteger("windowLeft", "left", _windowLeft)
  66.  
  67.  
  68.             WriteInteger("WindowHeight", "height", _windowHeight)
  69.             WriteInteger("WindowWidth", "width", _windowWidth)
  70.         End If
  71.  
  72.     End Sub
  73.     Public Sub Load()
  74.         Dim temptop As Integer = GetInteger("windowTop", "top", "0")
  75.         If temptop > 0 Then
  76.             _windowTop = temptop
  77.         Else
  78.             _windowTop = 0
  79.         End If
  80.         Dim templeft As Integer = GetInteger("windowLeft", "left", "0")
  81.         If templeft > 0 Then
  82.             _windowLeft = templeft
  83.         Else
  84.             _windowLeft = 0
  85.         End If
  86.         Form1.Location = New Point(WindowLeft, WindowTop)
  87.  
  88.         _windowHeight = GetInteger("WindowHeight", "height", "0")
  89.         _windowWidth = GetInteger("WindowWidth", "width", "0")
  90.  
  91.  
  92.         If (WindowWidth + templeft) < Screen.PrimaryScreen.WorkingArea.Width AndAlso (WindowHeight + temptop) < Screen.PrimaryScreen.WorkingArea.Height Then
  93.             form1.Height = WindowHeight
  94.             form1.Width = WindowWidth
  95.         Else
  96.             If (WindowWidth) < Screen.PrimaryScreen.WorkingArea.Width AndAlso (WindowHeight) < Screen.PrimaryScreen.WorkingArea.Height Then
  97.                 Dim centrex As Double = (Screen.PrimaryScreen.WorkingArea.Width - WindowWidth) / 2
  98.                 Dim centrey As Double = (Screen.PrimaryScreen.WorkingArea.Height - WindowHeight) / 2
  99.                 form1.Height = WindowHeight
  100.                 form1.Width = WindowWidth
  101.                 form1.Location = New Point(centrex, centrey)
  102.             Else
  103.                 form1.Location = New Point(5, 5)
  104.                 SubResize(form1, 95, 95)
  105.             End If
  106.         End If
  107.  
  108.  
  109.     End Sub
  110.  
  111.     Public Shared Sub SubResize(ByVal F As Form, ByVal percentW As Single, ByVal percentH As Single)
  112.         Dim FormHeight As Long
  113.         Dim FormWidth As Long
  114.  
  115.         'Calculate the new height and width the form needs to be resized to, based on the current avaible screen area.
  116.         FormHeight = Int((Screen.PrimaryScreen.WorkingArea.Height) * (percentH / 100))
  117.         FormWidth = Int((Screen.PrimaryScreen.WorkingArea.Width) * (percentW / 100))
  118.  
  119.         'Use the Form that is to be resized.
  120.         With F
  121.             'Change the demensions and position of the form.
  122.             .Height = FormHeight
  123.             .Width = FormWidth
  124.         End With
  125.  
  126.     End Sub
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement