Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Share imagelist in .Net Winforms application

I want to have ONE instance of an image list that I want to share over all the forms in my application(s) (icons for the toolbar). I've seen the question asked before and people came up with a user control (which is no good, since it will create multiple instances of the imagelist and thus create unnecessary objects and overhead).

Design time support would be good, but not very essential.

In Delphi this was pretty easy: create a DataForm, share the images and you are off.

Is there a C#/.Net/Winforms variantion on that?

like image 385
Bart Roozendaal Avatar asked Jan 24 '23 10:01

Bart Roozendaal


1 Answers

You could simply make a static class hold an ImageList instance, and use that in your application, I guess:

public static class ImageListWrapper
{
    static ImageListWrapper()
    {
        ImageList = new ImageList();
        LoadImages(ImageList);
    }

    private static void LoadImages(ImageList imageList)
    {
        // load images into the list
    }

    public static ImageList ImageList { get; private set; }
}

Then you can load images from the hosted ImageList:

someControl.Image = ImageListWrapper.ImageList.Images["some_image"];

No design time support in that solution though.

like image 101
Fredrik Mörk Avatar answered Feb 03 '23 22:02

Fredrik Mörk