O'Reilly logo

Microsoft® Visual Basic® .NET Programmer's Cookbook by Matthew MacDonald

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Save the Size and Location of a Form

Problem

You want to store the size and position of a resizable form and restore it the next time the form is shown.

Solution

Store the Left, Top, Width, and Height form properties in the registry.

Discussion

The registry is an ideal place for storing position and size information for a form. Typically, you’ll store each form in a separate key, perhaps using the class name of the form. These keys will be stored under an application-specific key.

To automate this process, it helps to create a dedicated class that saves and retrieves form settings. The FormSettingStore class shown in the following example fills this role. It provides a SaveSettings method that accepts a form and writes its size and position information ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required