If I have a form Frm1.c开发者_StackOverflow社区s that is using some icons, images or other resources, these resources get stored in the form's resx file (Frm1.resx).
My simple question is how do I access these resources from code?
As a workaround I can store these resources in the Project resource file and they will be available via Properties.Resources.resourcename
.
However, similar syntax does not work for the resources stored in the form's resource file.
While searching for a solution I have come across several references to ResourceManager class but was not able to find a way to use that to access the form's resources...
The way to access local form resources is through an instance of ResourceManager. Suppose you got two PictureBox in a Form called Frm1:
var resources = new ResourceManager(typeof(Frm1));
var image = (Bitmap)resources.GetObject("pictureBox1.Image");
pictureBox2.Image = image;
Hope this could help you...
If you use visual studio designer to add resources, you get a class Resources
with static properties to access them.
To access:
this.pictureBox1.Image = Properties.Resources.MyResourceImage;
精彩评论