[C# Helper]
Index Books FAQ Contact About Rod
[Beginning Database Design Solutions, Second Edition]

[Beginning Software Engineering, Second Edition]

[Essential Algorithms, Second Edition]

[The Modern C# Challenge]

[WPF 3d, Three-Dimensional Graphics with WPF and C#]

[The C# Helper Top 100]

[Interview Puzzles Dissected]

[C# 24-Hour Trainer]

[C# 5.0 Programmer's Reference]

[MCSD Certification Toolkit (Exam 70-483): Programming in C#]

Title: Use resources to hold images, text, and other data, and load it at run time in C#

Resources are images, strings, text files, and other pieces of data that you can build into an application. Your program can load the resources at run time to display new pictures, text, or whatever.

To add resources to the project, open the Project menu and select the Properties command at the very bottom. On the Properties page, click the Resources tab. Now you can use the Add Resource dropdown menu to add existing or new files to the program's resources.

When you add a resource to the program, C# creates a typed variable representing it named namespace.Properties.Resources.resourcename where namespace is the program's namespace and resourcename is the resource's name. For instance, in this example I added a jpg file named Earth.jpg, so the program can use the Bitmap variable Properties.Resources.Earth.

The example program displays a group of RadioButtons labeled Mercury, Venus, Earth, and so forth. When you click one, code similar to the following executes to display the corresponding resource.

private void radMercury_CheckedChanged(object sender, EventArgs e) { picPlanet.Image = Properties.Resources.Mercury; }

Download the example to experiment with it and to see additional details.

© 2009-2023 Rocky Mountain Computer Consulting, Inc. All rights reserved.