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
jasonboetcherAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

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

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
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
The Ultimate Tool Kit for Technolgy Solution Provi

Broken down into practical pointers and step-by-step instructions, the IT Service Excellence Tool Kit delivers expert advice for technology solution providers. Get your free copy for valuable how-to assets including sample agreements, checklists, flowcharts, and more!

É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
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Visual Basic Classic

From novice to tech pro — start learning today.