There are times when it’s handy for developers to be able to remember where a form was located the last time the application was used. In this quick VB.NET tip, I’ll show you a way of using Application Settings to store and use the last location of the form.
Using Application Settings
In order to store and use the form’s location, I will use the Location property of the My.Settings object. Follow these steps to access the My.Settings object:
- Click the Project Properties and then click the Settings tab.
- In the Settings tab, set the Name to MainFormLocation and set the Type to System.Drawing.Point.
- Open the Form’s properties and expand its Application Settings property. Find the Location property and set its value to MainFormLocation from the drop down list.
You are all set to use the application. Run it, then move the form, close, and re-run. The form should appear in the location where you last left it.
If you do the setup listed above, you will be able to programmatically access My.Settings.MainFormLocation (if necessary) since any settings added to the Settings tab of the Project Properties appear as the members of My.Settings object.
Irina Medvinskaya has been involved in technology since 1996. She has an MBA from Pace University and works as a project manager at Citigroup.
Get Visual Basic tips in your inbox
Advance your scripting skills to the next level with TechRepublic’s free Visual Basic newsletter, delivered each Friday. Automatically subscribe today!