• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 258
  • Last Modified:

Saving Form Sizes To The Registry

When a user changes the size of a form how can I save the new size to the registry so that next time the form is accessed it shows with the new size?  After a form has been resized and saved to the registry, how can I reset all forms in my project to their default sizes?  Thanks
0
jasonboetcher
Asked:
jasonboetcher
  • 3
  • 3
  • 2
1 Solution
 
James_stillmanCommented:
You can Save and get the values from registry

using the


            SaveSetting "YourAppName", "YourSectionName", "YourValueName",MyValue

eg:   SaveSetting "CoolSoft","CoolGame", "MyFormHeight",Form1.height


To get the values you have stored

     GetSetting("YourAppName", "YourSectionName", "YourValueName", "YourDefaultValue")

eg.

    form1.height = cint(GetSetting("CoolSoft", "CoolGame", "MyFormHeight", "100"))


0
 
James_stillmanCommented:
The getSettings would be performed during the loading of forms and the saveSettings would be performed during the form unloads.

Cheers

James  ;^)
0
 
Éric MoreauSenior .Net ConsultantCommented:
Use this code that read from/write to the registry.

Option Explicit

Private Sub Form_Load()
    Me.Top = GetSetting(App.Title, _
                        "Startup", _
                        "Top", _
                        200)
    Me.Left = GetSetting(App.Title, _
                        "Startup", _
                        "Left", _
                        200)
    Me.Height = GetSetting(App.Title, _
                        "Startup", _
                        "Height", _
                        2000)
    Me.Width = GetSetting(App.Title, _
                        "Startup", _
                        "Width", _
                        2000)
End Sub

Private Sub Form_Unload(Cancel As Integer)
    SaveSetting App.Title, _
                "Startup", _
                "Top", _
                Me.Top
    SaveSetting App.Title, _
                "Startup", _
                "Left", _
                Me.Left
    SaveSetting App.Title, _
                "Startup", _
                "Height", _
                Me.Height
    SaveSetting App.Title, _
                "Startup", _
                "Width", _
                Me.Width
End Sub
0
Never miss a deadline with monday.com

The revolutionary project management tool is here!   Plan visually with a single glance and make sure your projects get done.

 
Éric MoreauSenior .Net ConsultantCommented:
>After a form has been resized and saved to the registry, how can I reset all forms in my project to their default sizes?

I forgot this one:

Private Sub Form_Resize()
Dim x As Form

    For Each x In Forms
        x.Move x.Left, x.Top, Width, Height
    Next
End Sub  
0
 
jasonboetcherAuthor Commented:
Would I need to add a SaveSettings command to save the size of each control I have added to the form?  This seems like a lot of coding for such a small task.
0
 
Éric MoreauSenior .Net ConsultantCommented:
You probably resize the controls in your Form_Resize. Let this event do its job after changing its properties in the Form_Load.
0
 
James_stillmanCommented:
If you Resize the form you should have methods in the form Resize to alter the size and positioning of the controls. So no you shouldn't Save/Get Setting for all of the controls.

If you do put the repositioning/resizing of all of the controls in the form resize event. The event will be fired on form load and everything will be Nice.

Cheers

James
0
 
jasonboetcherAuthor Commented:
Thanks to both of you for your responses.  I gave James the points since he currently has the least.  I hope this is fair.
0

Featured Post

Keep up with what's happening at Experts Exchange!

Sign up to receive Decoded, a new monthly digest with product updates, feature release info, continuing education opportunities, and more.

  • 3
  • 3
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now