Partilhar via


Objeto My.Resources (Visual Basic)

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

Comentários

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

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 Demonstra Passo a passo: Localizando Windows Forms.

You can access the application's culture-specific resource files from the My.Resources object. Por padrão, o My.Resourcesobjeto procura de recursos que coincida com a cultura no arquivo de recurso a UICulturepropriedade. However, you can override this behavior and specify a particular culture to use for the resources. For more information, see Recursos em aplicativos.

Properties

As propriedades da My.Resources objeto fornecer acesso somente leitura a todos os recursos. do aplicativo To add or remove resources, use the Project Designer. For more information, see Como: Adicionar ou remover recursos. 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:

  • 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

O UnmanagedMemoryStream classe deriva o Stream classe, portanto, ele pode ser usado com os métodos que levam os fluxos, como o Play método.

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

Como: Recuperar os recursos de seqüência de caracteres no Visual Basic

Retrieve an image resource

Como: Recuperar os recursos de imagem no Visual Basic

Retrieve an icon resource

Como: Recuperar os recursos de ícone no Visual Basic

Retrieve an audio resource

Como: Recuperar os recursos de áudio no Visual Basic

Retrieve a localized resource

Como: Recuperar recursos localizados em Visual Basic

Exemplo

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 Como: Adicionar ou remover recursos.

Consulte também

Tarefas

Como: Recuperar os recursos de seqüência de caracteres no Visual Basic

Como: Recuperar os recursos de imagem no Visual Basic

Como: Recuperar os recursos de ícone no Visual Basic

Como: Recuperar os recursos de áudio no Visual Basic

Como: Recuperar recursos localizados em Visual Basic

Como: Adicionar ou remover recursos

Demonstra Passo a passo: Localizando Windows Forms

Conceitos

Recursos em aplicativos

Outros recursos

Gerenciando Recursos de Aplicativo