My.Resources Object

Provides properties and classes for accessing the application's resources.

Remarks

The My.Resources object provides access to the application's resources and lets you dynamically retrieve resources for your application. For more information, see Managing Application Resources.

The My.Resources object exposes only global resources. It does not provide access to resource files associated with forms. You must access the form resources from the form. For more information, see Walkthrough: Localizing Windows Forms.

You can access the application's culture-specific resource files from the My.Resources object. By default, the My.Resources object looks up resources from the resource file that matches the culture in My.Application.UICulture Property. However, you can override this behavior and specify a particular culture to use for the resources. For more information, see Resources in Applications.

Properties

The properties of the My.Resources object provide read-only access to your application's resources. To add or remove resources, use the Project Designer. For more information, see How to: Add or Remove Resources. You can access resources added through the Project Designer by using My.Resources.resourceName.

You can also add or remove resource files by selecting your project in Solution Explorer and clicking Add New Item or Add Existing Item from the Project menu. You can access resources added in this manner by using My.Resources.resourceFileName.resourceName.

Each resource has a name, category, and value, and these resource settings determine how the property to access the resource appears in the My.Resources object. For resources added in the Project Designer:

Classes

The My.Resources object exposes each resource file as a class with shared properties. The class name is the same as the name of the resource file. As described in the previous section, the resources in a resource file are exposed as properties in the class.

Tasks

The following table lists examples of tasks involving the My.Resources object.

To

See

Retrieve a string resource

How to: Retrieve String Resources in Visual Basic

Retrieve an image resource

How to: Retrieve Image Resources in Visual Basic

Retrieve an icon resource

How to: Retrieve Icon Resources in Visual Basic

Retrieve an audio resource

How to: Retrieve Audio Resources in Visual Basic

Retrieve a localized resource

How to: Retrieve Localized Resources in Visual Basic

Example

This example sets the icon of the form to the icon named Form1Icon that is stored in the application's resource file.

Sub SetFormIcon()
    Me.Icon = My.Resources.Form1Icon
End Sub

For this example to work, your application must have an icon named Form1Icon in the application's resource file. For more information, see How to: Add or Remove Resources.

See Also

Tasks

How to: Retrieve String Resources in Visual Basic

How to: Retrieve Image Resources in Visual Basic

How to: Retrieve Icon Resources in Visual Basic

How to: Retrieve Audio Resources in Visual Basic

How to: Retrieve Localized Resources in Visual Basic

How to: Add or Remove Resources

Walkthrough: Localizing Windows Forms

Concepts

Resources in Applications

Reference

My.Application.UICulture Property

Other Resources

Managing Application Resources