40.2. Resourcing Your Application

Writing an application often requires data such as images, icons, or sounds (collectively known as resources) to enhance the appearance of the application. Furthermore, best coding practices suggest that the use of constant strings throughout your application be avoided. In either case we can put together a custom solution that stores these resources in files that need to be shipped with the application.

An alternative is to include them in a resource file that can be compiled into your application. This way you not only have the resources in a format that you can work with, but they are also automatically available within your application.

In Visual Studio 2008, forms are initially represented by two files: the generated designer file (for example, Form1.Designer.vb) and the code-beside file (for example, Form1.vb). When a control, such as a button, is first added to the form, a resource file (for example, Form1.resx) is automatically created for the form. By default, this resource file contains very little data, as most properties are hard-coded into the designer file. This file becomes very important when localization is turned on for the form. When this is done, via the properties grid shown in Figure 40-5, the designer properties for the controls on the form are persisted to the resource file.

Figure 40.5. Figure 40-5

The following code ...

Get Professional Visual Studio® 2008 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.