Resource Basics

Imagine setting the background image of a form in your application by loading a bitmap from a file:

public Form1() {
  ...
  // Load a file from the file system
					this.BackgroundImage =
					new Bitmap(@"C:\WINDOWS\Web\Wallpaper\Azul.jpg");
}

The problem with this code is that not all installations of Windows will have Azul.jpg, and even those that do have it may not have it in the same place. Even if you shipped this picture with your application, a space-conscious user may decide to remove it, causing your application to fault. The only safe way to make sure that the picture, or any file, stays with code is to embed it and load it as a resource, a named piece of data embedded in the assembly itself.

Manifest Resources

Resources are added ...

Get Windows Forms Programming in C# now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.