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:
00976703
Vues:
11
This message has been marked as the solution to the initial question of the thread.
Einar,

If you have embedded resources you can use the ResourceManager class in the System.Resources namespace. There are lots of examples available but the following code shows you how to create a custom resource file and read from it (an image and a string).
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();
}

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"));
}
Three things to note.

1] The button1_Click event generates the resource file, you need to add this to your project and rebuild it with the Build Action as Embedded Resource.

2] You prefix the name of the resource with the Namespace otherwise you will get exceptions.

3] If you are using cultures then you will have to supply culture specific resources and use the overloaded GetObject passing in the correct culture.

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

Click here to load this message in the networking platform