简体   繁体   中英

Dynamically add Image to ImageList that lasts in C#

I have this code to add an Image to ImageList :

imageList1.Images.Add(Image.FromFile(path));

I want to somehow save the image in my application(resources maybe?!) just like the way you add Image to ImageList at design time so if I move my application files somewhere else the added images move with it. I don't want to save files in application path or database or other things like that.

Is there any way to do that ?

Can you logically explain how that should work? Did you think this through?

just like the way you add Image to ImageList at design time

If you do this, they get COMPILED INTO THE PROGRAM AS RESOURCE. Which not only requires the compiler and the source code (though you can put them into a resource only assembly), but also access to changing the program files.

Doable at compile time, totally not a sane approach at runtime.

It also effectively stored them in a resource assembly in the application path, which you rule out as a location.

I don't want to save files in application path or database or other things like that.

latest "other things like that" would ALSO rule out modifying the program (as it would store them somewhere) and make this a total fallacy request. You want to store images but not store them. Grats. Even if not:

  • Programs should NOT NEVER EVER modify themselves. This is a high priviledge operation, normal users can not change the program files folder.
  • As you rule out all other places - where you want to store the iamge? Cloud? Magic?

There is no way to do what you want because you rule out all possibilities. And "Like at design time" only seems to think you think this works by magic.

So, no - the question as you have asked it has one answer: get realistic. You can not rule out all ways to save them and then want them saved. Requirements contradict themselves.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM