Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
How can I set the image property at run time?
Message
General information
Forum:
ASP.NET
Category:
Forms
Miscellaneous
Thread ID:
00976594
Message ID:
00976757
Views:
12
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
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform