.net placement of image resources in forms

I got a little confused about whether to delete images and icon resources when they link to my forms. In particular, is there a difference in behavior if I refer to an image / icon from development-time resources or load an image at runtime. (.Net4, VS2015, C #)

Obviously, if you set the form icon property at design time to a resource, you do not explicitly express it Dispose()when the form closes. But what about this:

this.Icon = Resources.my_default_icon;

Do you need to get rid of this.Iconafter closing this form?

Similarly, what if I have a mini-class just for “branding” and I have a static object Iconthat loads (maybe from a file, maybe just refers to an embedded resource) at runtime? Should I use copy constructor in static Icongetter? Or is it okay to make it public static Iconand allow all my forms to have the following single-line font in their event _Shown()?

this.Icon = MyBrandingClass.formIcon;

Not sure if this is very different, I saw some links to setting the image in boot mode at runtime and disposing of the image, but would you choose a built-in resource image? If I give a link to my branding image, can / should I refuse to post? Or should I use the constructor instance in getter to return a new Image object and then always delete it when the form is complete?

+4
source share
3 answers

A program should delete images when they are no longer needed, however this does not necessarily mean that it is your code that should do this.

In the first example, when you do:

this.Icon = Resources.my_default_icon;

ResourceManager. Resource.Designer.cs, .

"" . , , , ResourceManager ( , )

:

this.Icon = MyBrandingClass.formIcon;

ResourceManager .

MyBrandingClass , , . ? MyBrandingClass . , , MyBrandingClass, , .

, , , MyBrandingClass ResourceManager. , , ResourceManager (, MyBrandingClass). , Resource.Designer.cs, , , , ResourceManager (, ?)

, , , Resource. , , " ". , , . , , , . , , , ( ).

+3

(Resources MyBrandingClass), , .

Resources , , , .

MyBrandingClass, , - , . , .

IDisposable , , . Icon, , , , , . , .

+1

, , . , . .

. , . BMP.

0

Source: https://habr.com/ru/post/1669728/


All Articles