Atlanta Custom Software Development 

 
   Search        Code/Page
 

User Login
Email

Password

 

Forgot the Password?
Services
» Web Development
» Maintenance
» Data Integration/BI
» Information Management
Programming
  Database
Automation
OS/Networking
Graphics
Links
Tools
» Regular Expr Tester
» Free Tools

Save and reload form settings from system registry

Total Hit ( 2177)

Rate this article:     Poor     Excellent 

 Submit Your Question/Comment about this article

Rating


 


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
' Save form settings

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

' Restore form settings.

Function LoadFormSettings(ByVal AppName As String, frm As Object)
  Dim currWindowState As Integer

  ' in case no value is in the registry
  On Error Resume Next

  ' If the form is currently maximized or minimized, temporarily
  ' revert to normal state, otherwise the Move command fails.
  currWindowState = frm.WindowState
  If currWindowState <> 0 Then frm.WindowState = 0
  
  ' Use a Move method to avoid multiple Resize and Paint events.
  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

' Delete form settings

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


Submitted By : Nayan Patel  (Member Since : 5/26/2004 12:23:06 PM)

Job Description : He is the moderator of this site and currently working as an independent consultant. He works with VB.net/ASP.net, SQL Server and other MS technologies. He is MCSD.net, MCDBA and MCSE. In his free time he likes to watch funny movies and doing oil painting.
View all (893) submissions by this author  (Birth Date : 7/14/1981 )


Home   |  Comment   |  Contact Us   |  Privacy Policy   |  Terms & Conditions   |  BlogsZappySys

© 2008 BinaryWorld LLC. All rights reserved.