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 (.NET).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.My.Resources
object. By default, the My.Resources
object looks up resources from the resource file that matches the culture in the UICulture property. However, you can override this behavior and specify a particular culture to use for the resources. For more information, see Resources in Desktop Apps.My.Resources
object provide read-only access to your application's resources. To add or remove resources, use the Project Designer. You can access resources added through the Project Designer by using My.Resources.
resourceName.My.Resources.
resourceFileName.
resourceName.My.Resources
object. For resources added in the Project Designer: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 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. |
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.Form1Title
in the application resource file. For the example to work, the application must have a string named Form1Title
in its resource file.Form1Icon
that is stored in the application's resource file. For the example to work, the application must have an icon named Form1Icon
in its resource file.Form1Background
, which is in the application resource file. For this example to work, the application must have an image resource named Form1Background
in its resource file.Form1Greeting
in the application's resource file. For the example to work, the application must have an audio resource named Form1Greeting
in its resource file. The My.Computer.Audio.Play
method is available only for Windows Forms applications.Message
. To change the culture that the My.Resources
object uses, the example uses ChangeUICulture.Message
in its resource file, and the application should have the French-culture version of that resource file, Resources.fr-FR.resx. If the application does not have the French-culture version of the resource file, the My.Resource
object retrieves the resource from the default-culture resource file.ShowUI
parameter is set to True
, a dialog box is displayed showing the progress of the download and allowing users to cancel the operation. By default, existing files having the same name are not overwritten; if you want to overwrite existing files, set the overwrite
parameter to True
.connectionTimeout
(TimeoutException).DownloadFile
method to download the file, specifying the target file's location as a string or URI and specifying the location at which to store the file. This example downloads the file WineList.txt
from http://www.cohowinery.com/downloads
and saves it to C:Documents and SettingsAll UsersDocuments
:DownloadFile
method to download the file, specifying the target file's location as a string or URI, specifying the location at which to store the file, and specifying the time-out interval in milliseconds (the default is 1000). This example downloads the file WineList.txt
from http://www.cohowinery.com/downloads
and saves it to C:Documents and SettingsAll UsersDocuments
, specifying a time-out interval of 500 milliseconds:DownLoadFile
method to download the file, specifying the target file's location as a string or URI and specifying the location at which to store the file, the user name, and the password. This example downloads the file WineList.txt
from http://www.cohowinery.com/downloads
and saves it to C:Documents and SettingsAll UsersDocuments
, with the user name anonymous
and a blank password.DownLoadFile
method sends information, including passwords, in plain text and should not be used for transmitting sensitive information.