Visual Basic
Visual Basic.Net
Downloads
Links
Support This Site
Contact
This small tutorial is to show you how you can create your own properties to display under the 'My.MySettings' Class. This article will focus
on adding Two(2x) new properties/settings called: ApplicationSize and ApplicationPosition. I will use them to store the applications position
and Size when it exits or closes. Then the next time the application/program loads, it will use these settings and remember the exact Position
and Size from the last time it was opened and closed. This is a potentially nice feature that you can add to your applications to give a more user-friendly
experience.
Once you have your project loaded, goto the 'Project' menu and select the 'Properties' option from the list, which is usually the last item listed.
Then select the "Settings" Tab item. You will then see the settings grid which is used to configure the application settings.
Name: This is where you put the name of your property/setting. For this tutorial, put in ApplicationPosition as a name, and ApplicationSize as another name.
ApplicationSetting and ApplicationSize will actually be listed under: My.MySettings.Default.
Type: Here you can select the type you want your setting/property to be. Example: Point, Size, Date, Integer, and so on. For the article, set the type
for ApplicationPosition to be: 'Point'. For the ApplicationSize set to be the: 'Size' type.
Scope: This is where you can specify if the property/setting can only be modified by your Application, or if the person using your application can change the
setting. If 'Application' is set, then the user cannot modify the setting at runtime. If 'User' is selected, then the setting Can be modified at runtime by the user.
If you want to have certain preferences that the user can modify, then 'User' is the scope you want to use. For the article I went ahead and set it to 'User'.
Value: You can specify a default value for the property/setting that will be used if the property is being used for the first time or no other value have been
specified at runtime. This value will also be used if you 'Reset' the properties. Example: My.MySettings.Default.Reset() will reset the settings to your original values.
If you are following the article as a exercise, then your Project Properties should look similar to the picture below.
Under the: My.Settings.Default interface, you should have: My.MySettings.Default.ApplicationPosition and My.MySettings.Default.ApplicationSize available as properties
that can now be used. To get your application to use these properties and enable it to remember the size and position to load, you will want to put a few lines of code in
the Form_Load event, and the Form_FormClosing event.
Form_Load Event put:
Me.Location = My.MySettings.Default.ApplicationPosition
Me.Size = My.MySettings.Default.ApplicationSize
My.MySettings.Default.ApplicationPosition = Me.Location
My.MySettings.Default.ApplicationSize = Me.Size