Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
How can I set the image property at run time?
Message
Information générale
Forum:
ASP.NET
Catégorie:
Formulaires
Divers
Thread ID:
00976594
Message ID:
00976757
Vues:
11
Einar,

Apologies, I should have explained better. I create my resource files using code which I must then either attach into the project and recompile, or, attach and compile to another project as a satellite assembly.

The manually building of a resource file is what the first click (button1_Click) is showing. The result of this is the serialization of the bitmap and string into a resource file, not embedding the bitmaps directly into the project and ultimately the executable image!
private void button1_Click(object sender, System.EventArgs e)
{
   ResourceWriter imageResource = new ResourceWriter("quotes.resources");

   Image testImage = Image.FromFile(@"c:\test.bmp");

   imageResource.AddResource("msg1", "This is a string");
   imageResource.AddResource("neil", testImage);
   imageResource.Close();
}
Once you have an exe or dll that has been compiled with the embedded resource file the code in button2_Click shows how to extract the types from the resource file.
private void button2_Click(object sender, System.EventArgs e)
{
   ResourceManager imageResManager = new ResourceManager("WindowsApplication1.quotes", Assembly.GetExecutingAssembly());
	
   pictureBox1.Image = (Image)imageResManager.GetObject("neil");
   MessageBox.Show((string)imageResManager.GetObject("msg1"));
}
Using satellite assemblies is great for centralising, localised resources.

Regards
Neil
Précédent
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform