FormWinRegPos

By | 2002-04-20

This Procedure can be used by AnyForm to Get or Save the Form Position from the Windows Registry using SaveSetting and GetSetting 🙂

Original Author: Brad Skidmore

Inputs

pMyForm As Form
Optional pbSave As Boolean

Assumptions

Best to use this in either Form_Load, Form_Unload or Form_QueryUnload
Form_Load For Getting the Saved Form Posn Settings
Unload or QueryUnload for saveing Current Form Posn.

Code

Option Explicit
Public Sub FormWinRegPos(pMyForm As Form, Optional pbSave As Boolean)
  'This Procedure will Either Retrieve or Save Form Posn values
  'Best used on Form Load and Unload or QueryUnLoad
  On Error GoTo EH
  
  With pMyForm
    If pbSave Then
      'If Saving then do this...
      'If Form was minimized or Maximized then Closed Need to Save Windowstate
      'THEN... set Back to Normal Or previous non Max or Min State then Save
      'Posn Parameters SaveSetting App.EXEName, .Name, "Top", .Top
      SaveSetting App.EXEName, .Name, "WindowState", .WindowState
      If .WindowState = vbMinimized Or .WindowState = vbMaximized Then
        .WindowState = vbNormal
      End If
      'Save AppName...FrmName...KeyName...Value
      SaveSetting App.EXEName, .Name, "Top", .Top
      SaveSetting App.EXEName, .Name, "Left", .Left
      SaveSetting App.EXEName, .Name, "Height", .Height
      SaveSetting App.EXEName, .Name, "Width", .Width
    Else
      'If Not Saveing Must Be Getting ..
      'Need to ref AppName...FrmName...KeyName (If nothing Stored Use The Exisiting Form value)
      .Top = GetSetting(App.EXEName, .Name, "Top", .Top)
      .Left = GetSetting(App.EXEName, .Name, "Left", .Left)
      .Height = GetSetting(App.EXEName, Name, "Height", .Height)
      .Width = GetSetting(App.EXEName, .Name, "Width", .Width)
      'Be Sure WindowState is set last (Can't Change POSN if vbMinimized Or Maximized
      .WindowState = GetSetting(App.EXEName, .Name, "WindowState", .WindowState)
    End If
  End With
  
  Exit Sub
EH:
  MsgBox "Error " & Err.Number & vbCrLf & vbCrLf & Err.Description
  
End Sub

Private Sub Form_Load()
  FormWinRegPos Me
End Sub

Private Sub Form_Unload(Cancel As Integer)
  FormWinRegPos Me, True
End Sub

Date:2002-06-01

Migrated:Not Migrated

listview

How to move items (up ,down) in a listview

Original Author: John White

Attachments

FileUploadedSize
CODE_UPLOAD3779342000.zip9/3/2020 3:45:00 PM2876
Author: dwirch

Derek Wirch is a seasoned IT professional with an impressive career dating back to 1986. He brings a wealth of knowledge and hands-on experience that is invaluable to those embarking on their journey in the tech industry.

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.