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 allows you to 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. Resources added through the Project Designer are accessed using **My.Resources.**resourceName.

You can also add or remove resource files by selecting your project in Solution Explorer and choosing Add New Item or Add Existing Item from the Project menu. Resources added this way are available 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:

  • The name determines the name of the property,

  • The resource data is the value of the property,

  • The category determines the type of the property:

    Category Property data type

    Strings

    String

    Images

    Bitmap

    Icons

    Icon

    Audio

    UnmanagedMemoryStream

    The UnmanagedMemoryStream class derives from the Stream class, so it can be used with methods that take streams, such as the My.Computer.Audio.Play Method.

    Files

    • String for text files.

    • Bitmap for image files.

    • Icon for icon files.

    • UnmanagedMemoryStream for sound files.

    Other

    Determined by the information in the designer's Type column.

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

Reference

My.Application.UICulture Property

Concepts

Resources in Applications

Other Resources

Managing Application Resources