Use Strongly Typed Resources
In addition to code, .NET assemblies can also contain
resources—embedded binary data such as images and
hardcoded strings. Even though .NET has supported a system of resources
since Version 1.0, Visual Studio hasn't included integrated design-time
support. As a result, developers who need to store image data usually add it to a control that supports it at
design time, such as a PictureBox
or
ImageList
. These controls insert the
picture data into the application resource file automatically.
Note
Strongly typed resources let you embed static data such as images into your compiled assemblies, and access it easily in your code.
In Visual Studio 2005, it's dramatically easier to add information to the resources file and update it afterward. Even better, you can access this information in a strongly typed fashion from anywhere in your code.
How do I do that?
In order to try using a strongly typed resource of an image in this lab, you need to create a new Windows application before continuing.
To add a resource, start by double-clicking the My Project node in the Solution Explorer. This opens up the application designer, where you can configure a host of application-related settings. Next, click the Resources tab. In the Categories drop-down listbox, select the type of resources you want to see (strings, images, audio, and so on). The string view shows a grid of settings. The image view is a little different—by default, it shows a thumbnail of each picture.
To ...
Get Visual Basic 2005: A Developer's Notebook now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.