|Important||This document may not represent best practices for current development, links to downloads and other resources may no longer be valid. Current recommended version can be found here. ArchiveDisclaimer|
Resources and Settings Sample
This sample demonstrates how to manage resources and settings for an application using the My.Settings object, the My.Resources object, the Project Designer, and the Resource Editor.
This sample code is provided to illustrate a concept and should not be used in applications or Web sites, as it may not illustrate the safest coding practices. Microsoft assumes no liability for incidental or consequential damages should the sample code be used for purposes other than as intended.
To open the sample file in Solution Explorer
Click Download Sample.
The File Download message box appears.
Click Open, and on the left column of the zip folder window, click Extract all files.
The Extraction Wizard opens.
Click Next. You can change the directory that the files will be extracted to, and then click Next again.
Make sure that the Show extracted files check box is selected, and click Finish.
Double-click the sample's .sln file.
The sample solution is displayed in Solution Explorer. You might get a security warning that says the solution location is not trusted. Click OK to continue.
To run this sample
Each time you run the application, a different background is displayed.
A setting is used to keep track of the number of times the application has been run. Each time the application runs, the setting is examined, and one of several available desktop images is selected based on that number. Consequently, each time you run the application you see a new background.
The code resides in the SetBackground method of Form1 and within the application startup and shutdown events, which are handled in My Project\MyEvents.vb. To view this file, double-click My Project in Solution Explorer. On the Application panel of the Project Designer, click the View Application Events button.
Settings are created and modified on the Settings tab of the Project Designer. There are two types of settings: application and user. Application settings are those with values that are common to all instances of the application. User settings are created and modified for each user. In this sample, the setting that persists the number of times an installation of the application has been executed is a user setting.