If I have a form Frm1.cs 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...
Create an App_GlobalResources system folder and add a resource file to it e.g. Messages. resx. Create your entries in the resource file e.g. ErrorMsg = This is an error. Then to access that entry: string errormsg = Resources.
resx file in the XML (Text) editor. Press Alt+\ or choose ReSharper | Navigate | Go to File Member… from the main menu . Alternatively, you can press Ctrl+Shift+A , start typing the command name in the popup, and then choose it there. You will see the list of resource entries in a popup.
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 love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With