ImageList and liststyleimage

Source: Internet
Author: User

ImageList and liststyleimage

The ImageList component has been used for a long time, but it has never been quite clear about its implementation principles. Today, I spent a lot of time trying to figure it out! So here we will share with you!

On the Design page, find the ImageList component in the logging toolbox-component, drag it directly to the page, and the initialization code is automatically generated in the design as follows:

1 //. designer. the initialization code automatically generated on the cs design page is 2 private System. windows. forms. imageList imageList1; 3 // 4 // imageList1 5 // 6 this. imageList1.ImageStream = (System. windows. forms. imageListStreamer) (resources. getObject ("imageList1.ImageStream"); 7 this. imageList1.TransparentColor = System. drawing. color. transparent; 8 this. imageList1.Images. setKeyName (0, "open. ico "); 9 this. imageList1.Images. setKeyName (1, "save. ico "); 10 this. imageList1.Images. setKeyName (2, "quit. ico "); 11 this. imageList1.Images. setKeyName (3, "delete. ico ");

Open the Properties window on the design page and click the three dots next to Images to open the Image Set Editor, as shown in:

Clicking the Add button will directly load images from the local machine to ImageList. Here is a question: how can I add images? Is it a path or a second-level stream? If it is an image, you should be able to see the image path in the Properties window on the right, but not here. This indicates that the image is saved as a binary stream or an image stream. By referring to the initialization code on the previous design page, we can also see that during initialization, the program directly loads the image stream using the resources object, but here it cannot see where it loads it, first, we need to understand what the resources object is? Let's take a look at the Declaration of this object:

1 System. ComponentModel. ComponentResourceManager resources = new System. ComponentModel. ComponentResourceManager (typeof (FrmImportCardInfo); 2 // Abstract: 3 // provides simple functions for enumeration resources of components or objects. The System. ComponentModel. ComponentResourceManager class is a System. Resources. ResourceManager class. 4 public class ComponentResourceManager: ResourceManager

From the code above, we can see that resources is actually the object of the class ComponentResourceManager, and this class inherits from the ResourceManager class, which is obviously a class used to manage local resources. After finding this information, we can see that the image we added exists in the local resource. During the design of each form, if an image or other resource class object is added, a file is automatically generated, that is, the extension name. if the resx file does not exist, each form usually has two files :. cs files and. designer. cs file.

Double-click the. resx file in the project to open the. resx file. The visual interface is displayed.

Resources added to the form are in this file by default, unless the Resources. resx Resource class file is added to the project. It can be seen that the name of the added resource class is the same as the name of the resource introduced by the code automatically generated on the design page: resources. getObject ("imageList1.ImageStream"), so here we have determined that the added image is indeed saved in. in the resx file. However, we cannot see its value on this page. However, we can open the file in Notepad (the most terrible program of the mobile device ),

It can be seen that its value is stored in the file in base64 encoding format. Therefore, all added images are saved directly in the project rather than the address. If you Copy ImageList directly to other pages, a resource file is created in the corresponding form to save the image.

Link to my original Website: ImageList

 

Related Article

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.