A global ImageList ?

  • Thread starter Thread starter Omega
  • Start date Start date
O

Omega

Hi,

I have an ImageList and I want to use it at design time in several forms,
how can I do it ?

Ok, I can copy the ImageList from one form and paste it on the new form,
but these ImageLists are then duplicate.

Thanks
 
create static class somewhere, maybe Program.cs that loads the image list
into a variable.

public static class GlobalItems
{
private static ImageList _imgList=null;

public static ImageList GlobalImages
{
get
{
if (_imgList == null)
LoadImages();
return _imgList;
}
}

private static void LoadImages()
{
// Put your loading code here
}
}

then where ever you need to use it call

Namespace.GlobalItems.GlobalImages;
If you are setting the ImageList at DesignTime, you might need to change the
Form1.Designer.cs file.
 
Omega,

Is the image list going to be shared at runtime also. I don't think this is
a good OO design. If you need the image list just in design time you can
create and register a service upon loading your designer. Then you can look
for this service and get the image list from there in all your designers.
 
Omega,

Is the image list going to be shared at runtime also. I don't think this is
a good OO design. If you need the image list just in design time you can
create and register a service upon loading your designer. Then you can look
for this service and get the image list from there in all your designers.

Hi,

Sure, I want these images to be shared at rumtime also.

The problem: I have same buttons like 'Search' / 'Info' on different forms,
the button has an icon on the left, I can choose the icon from the
ImageList which is already resized (16x16). Everything is ok but the
ImageList must be on every form.

I tried to create a resource for the project and add icons to it, it will
be global for all the forms in the project, in button's Image propertys I
then choose the resource icon but it can't be resized, it is always the
first icon in the Ico file (48x48).

Create and register a service ? I don't know how to do it ...

Omega
 
Omega,

I don't think is a necessary a bad idea to have image list on each form.
Anyways, look at Icon class constructors, there are overloads that accept
size. Besically you load an icon form the resource and then create a new
Icon instance out of the loaded one specifying the size. This will extract
the icon with sepcified size.

Icon icon = new Icon(typeof(...), "MyIcon.ico");
Icon icon16 = new Icon(icon, 16,16);


There is also overlaod that accept stream and size. I think it works on the
same way, but never tried it.

As you can pick different image sizes there is no solution for getting same
size, but different color depth For example if you have and icon file with
images 16x16x16 and 16x16x256 you cannnot cotrol which one the Icon
constructor will pick. My test shows it picks 256-color one.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top