Recipe 5.35. Adding Strings to an Application's Resources
You need to store and edit strings in an application's resources. This makes it easy to internationalize the application by changing the strings for each culture.
To edit the resource strings in the Visual Studio environment, open the project's properties page, and select the Resources tab on the left. Edit the table of string entries, changing the Name, Value, and Comment fields as required.
In the application, refer to each string through the My.Resources object.
In Visual Studio, it's very easy to maintain a table of strings in the application's resources. Figure 5-39 shows the project's properties page with the Resources tab selected along the left side.
Figure 5-39. Editing resource strings in Visual Studio
The example shows two resource strings, one named Caption and the other named Text. As the following code shows, in the application these two strings are referenced by name through the My.Resources object. This code then displays a message box using the two strings from the resources, as shown in Figure 5-40:
Dim stringText As String = My.Resources.Text Dim stringCaption As String = My.Resources.Caption MsgBox(stringText, , stringCaption)
Figure 5-40. The results of editing the message box's Caption and Text properties
Other types of resources can be added, such as images, sounds, and other files. Each of these resources is accessed in the application through the My.Resources object.
See Chapter 10for an example of storing and using media files in your application's resources.