Save and reload form settings from system registry

Save and reload form settings from system registry

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.

' Save form settingsFunction 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.WindowStateEnd 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 settingsSub DeleteFormSettings(ByVal AppName As String, frm As Object)    DeleteSetting AppName, frm.nameEnd Sub

Using these routines is straightforward:

Private Sub Form_Load()    LoadFormSettings "MyApp", MeEnd SubPrivate Sub Form_Unload(Cancel As Integer)    SaveFormSettings "MyApp", MeEnd Sub

Share the Post:
Heading photo, Metadata.

What is Metadata?

What is metadata? Well, It’s an odd concept to wrap your head around. Metadata is essentially the secondary layer of data that tracks details about the “regular” data. The regular

XDR solutions

The Benefits of Using XDR Solutions

Cybercriminals constantly adapt their strategies, developing newer, more powerful, and intelligent ways to attack your network. Since security professionals must innovate as well, more conventional endpoint detection solutions have evolved

AI is revolutionizing fraud detection

How AI is Revolutionizing Fraud Detection

Artificial intelligence – commonly known as AI – means a form of technology with multiple uses. As a result, it has become extremely valuable to a number of businesses across

AI innovation

Companies Leading AI Innovation in 2023

Artificial intelligence (AI) has been transforming industries and revolutionizing business operations. AI’s potential to enhance efficiency and productivity has become crucial to many businesses. As we move into 2023, several