Summarize a method of how to use resources in C #:
One: Using local files
1, the local to join the resources text (video, pictures, text or other) into the project, for example, we now add a up.bmp picture to the project, and placed under the folder resources,
2. Set the build action of up.bmp to "embedded Resource"
3. Read resources:
Assembly Assembly = assembly.getentryassembly ();
I do not know why, the above sometimes not, can write: Assembly Assembly = this. GetType (). Assembly;
System.IO.Stream Stream = assembly. GetManifestResourceStream ("OutlookBar.Resources.up.bmp");
OutlookBar represents a namespace, and resources represents a folder name;
If the check is placed directly in the root directory of the project, it is written as: assembly. GetManifestResourceStream ("OutlookBar.up.bmp");
Bitmap upimage = (Bitmap) image.fromstream (stream);
The second method: Create a new. resx file (testproject.resx) and join the Up.bmp file directly,
Read method: Bitmap upimage = testproject.up;
Third method: Create a separate resource file to store the Up.bmp file
1: Write to:
if (! File.exists ("Testproject.resources"))
File.create ("Testproject.resources"). Dispose ();
using (iresourcewriter RW = new ResourceWriter ("Testproject.resources"))
{
Image img = image.fromfile (@ "D:\up.bmp");
rw. AddResource ("Up.bmp", IMG);
rw. Close ();
}
2. Read the file
using (ResourceSet rs = new ResourceSet ("Testproject.resources"))
{
var image = (Bitmap) Rs. GetObject ("Down.bmp");
pictureBox1.Image = Image;
Rs. Close ();
}
NET resources are not limited to. resx files and can be used in any storage format
: See http://www.cnblogs.com/artech/archive/2010/12/16/Reource_framewok_01.html for details
Ways to use resources in C #