O'Reilly logo

Windows Forms Programming in C# by Chris Sells

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

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 ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required