VB icon

FormWinRegPos

Email
Submitted on: 1/5/2015 10:43:00 AM
By: Brad Skidmore (from psc cd)  
Level: Intermediate
User Rating: By 4 Users
Compatibility: VB 5.0, VB 6.0
Views: 583
 
     This Procedure can be used by AnyForm to Get or Save the Form Position from the Windows Registry using SaveSetting and GetSetting :)
 
code:
Can't Copy and Paste this?
Click here for a copy-and-paste friendly version of this code!
				
'**************************************
' Name: FormWinRegPos
' Description:This Procedure can be used by AnyForm to Get or Save the Form Position from the Windows Registry using SaveSetting and GetSetting :)
' By: Brad Skidmore (from psc cd)
'
' Inputs:pMyForm As Form
Optional pbSave As Boolean
'
' Assumes: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.
'**************************************

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


Other 3 submission(s) by this author

 


Report Bad Submission
Use this form to tell us if this entry should be deleted (i.e contains no code, is a virus, etc.).
This submission should be removed because:

Your Vote

What do you think of this code (in the Intermediate category)?
(The code with your highest vote will win this month's coding contest!)
Excellent  Good  Average  Below Average  Poor (See voting log ...)
 

Other User Comments


 There are no comments on this submission.
 

Add Your Feedback
Your feedback will be posted below and an email sent to the author. Please remember that the author was kind enough to share this with you, so any criticisms must be stated politely, or they will be deleted. (For feedback not related to this particular code, please click here instead.)
 

To post feedback, first please login.