Store last position and size of every form
Posted: 2019-08-29
By: AndreaTincani
Viewed: 338
Filed Under:
VB6 Custom Controls/Forms/Menus, VB6 Miscellaneous, VB6 Code Cache
No attachments for this post
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
Special Instructions
This code originally appeared on AndreaVB.com, and has been republished here with the permission of Andrea Tincani.
Comments on this post
No comments have been added for this post.
You must be logged in to make a comment.