C # embedded Resources

Source: Internet
Author: User

1. Manual embedded Resources
Right-click Project-add-existing item-image or text
Click image or text-generate operation-Embedded resources // this step is very important
In this way, the added image or text will be packaged into the exe.
You can access:
Assembly = GetType (). assembly;
System. Io. Stream streamsmall = assembly. getmanifestresourcestream ("windowsformsapplication1.event.jpg ");
// When a resource is embedded, the complete name of the resource is composed of the project's default namespace and file name.
Bitmap backgroundimg = new Bitmap (streamsmall );
Picturebox1.image = backgroundimg;

Assembly = GetType (). assembly;
System. Io. Stream streamsmall = assembly. getmanifestresourcestream ("windowsformsapplication1.newfolder1.textfile1.txt ");
Streamreader sr = new streamreader (streamsmall );
String text = Sr. readtoend ();
MessageBox. Show (text );

2. Manual non-embedded Resources
Right-click Project-add-existing item-image or text
Click image or text-generate operation-content// If no operation is performed, non-embedded resources are used by default.
In this way, the added image or text will be packaged into the exe.
You can access:
Use the absolute path and relative path to access external resources

//////////////////////////////////////// /////
3. Access embedded resources provided by. net

Resources. resx, form1.resx how to use?// You only need to add the resource without any operation. The default value is embedded resource.

Each time you create a form, A. resx file is automatically generated. Strings, images, icons, and files can be added to the file.
When the project is compiled, an EXE file is generated, and all the images, icons, and files are written into the EXE file.

Each form has a resource file and the project has a shared resource file. It is best to use this shared resource file to view the project attributes and select resources,

You can add the resources you want to add resources-add existing files, and you can put the anti-image resources in.

Read the image resource. If an a.bmp image has been added, the image name is pic.

Bitmap bitmap = project namespace. properties. Resources. PIC;
This resource may be used.

The specific class is located in the resources. resx file in the properties directory. Open it and you will understand it.

Resource files can also be created by yourself, such as creating a class.

This kind of embedded resource access method is provided by. Net internally. Similar to accessing app. config, it is provided by. Net internally. Of course, you can also use 1 to manually create

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.