Use a separate DLL to store images (resource files)

Source: Internet
Author: User
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")));

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.