You can put VB's registry functions to good use by creating a few reusable routines that save, reload, and delete size and state of a form in your program. |
Click here to copy the following block |
Function SaveFormSettings(ByVal AppName As String, frm As Object) SaveSetting AppName, frm.Name, "Left", frm.Left SaveSetting AppName, frm.Name, "Top", frm.Top SaveSetting AppName, frm.Name, "Width", frm.Width SaveSetting AppName, frm.Name, "Height", frm.Height SaveSetting AppName, frm.Name, "WindowState", frm.WindowState End Function
Function LoadFormSettings(ByVal AppName As String, frm As Object) Dim currWindowState As Integer
On Error Resume Next
currWindowState = frm.WindowState If currWindowState <> 0 Then frm.WindowState = 0 frm.Move GetSetting(AppName, frm.Name, "Left", frm.Left), _ GetSetting(AppName, frm.Name, "Top", frm.Top), GetSetting(AppName, _ frm.Name, "Width", frm.Width), GetSetting(AppName, frm.Name, "Height", _ frm.Height) frm.WindowState = GetSetting(AppName, frm.Name, "WindowState", _ currWindowState) End Function
Sub DeleteFormSettings(ByVal AppName As String, frm As Object) DeleteSetting AppName, frm.name End Sub
Using these routines is straightforward: Private Sub Form_Load() LoadFormSettings "MyApp", Me End Sub
Private Sub Form_Unload(Cancel As Integer) SaveFormSettings "MyApp", Me End Sub |
|