Using an independent DLL to store images, you can put all the image files we want to use in one DLL, so that there are not so many image files in the project. 1. add a new class project picresource to the solution, copy the image folder skin to the project directory, and include the skin in the project; 2. in the newly created Project, select all the images in the skin folder and change the build action attribute to embedded resource in the property. 3. compile the project to generate a picresource. DLL 4. add a Windows application project winappdemo1 for testing in the solution. copy DLL to winappdemo1 \ bin \ debug; 5. add a button to the form in the test project to create a picturebox resource path: <namespace>. <subfolders>. <image name>. <extension> (<namespace>. <folder>. <image name>. <suffix>) Code : Private void button#click (Object sender, eventargs e) {Assembly myassembly = assembly. loadfrom ("picresource. DLL "); stream mystream = myassembly. getmanifestresourcestream ("picresource.skin.right.bmp"); bitmap BMP = new Bitmap (mystream); picturebox1.image = BMP;} If you have clicked button1, you can see the image in picturebox. OK, if it is successfully placed in the project-> properties. resources. the resx file is used:
-
C # code
-
Image img=(Image) namespace. properties. Resources. Resource Name;
For external use, all resources. resx [resources] are defined as public.
If the file *. resx is stored in the CS file, use:
-
C # code
-
Image img=(Image )(NewComponentresourcemanager (Typeof(Class Name). GetObject ("Control name. property name")));