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 ...

Get Microsoft® Visual Basic® .NET Programmer's Cookbook now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.