Use this code to store last position and size of every form in your project, every form will be loaded in the state and position of the last time it was opened.
Use this code to store last position and size of every form in your project every form will be loaded in the state and position of the last time it was opened since it uses App.Title and Me.Name to store values in the registry it can be used “as is” just by pasting it into your forms’ Load and Unload events.
Private Sub Form_Load()
'load settings from the registry
Me.WindowState = GetSetting(App.Title, Me.Name, "WindowState", Me.WindowState)
If Me.WindowState = vbNormal Then
Me.Width = GetSetting(App.Title, Me.Name, "Width", Me.Width)
Me.Height = GetSetting(App.Title, Me.Name, "Height", Me.Height)
Me.Left = GetSetting(App.Title, Me.Name, "Left", Me.Left)
Me.Top = GetSetting(App.Title, Me.Name, "Top", Me.Top)
End If
End Sub
Private Sub Form_Unload(Cancel As Integer)
'Save orm dimensions and state in the registry
SaveSetting App.Title, Me.Name, "WindowState", Me.WindowState
If Me.WindowState = vbNormal Then
SaveSetting App.Title, Me.Name, "Height", Me.Height
SaveSetting App.Title, Me.Name, "Width", Me.Width
SaveSetting App.Title, Me.Name, "Left", Me.Left
SaveSetting App.Title, Me.Name, "Top", Me.Top
End If
End Sub