Search Tools Links Login

Site Hosting Changing Soon: Might be a bit of down time. Sorry for the inconvenience.

Store last position and size of every form


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

About this post

Posted: 2019-08-29
By: AndreaTincani
Viewed: 399 times

Categories

Visual Basic 6

Attachments

No attachments for this post

Special Instructions

This code originally appeared on AndreaVB.com, and has been republished here with the permission of Andrea Tincani.


Loading Comments ...

Comments

No comments have been added for this post.

You must be logged in to make a comment.