468,507 Members | 1,580 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 468,507 developers. It's quick & easy.

A global ImageList ?

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
Dec 21 '05 #1
4 6496
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.
Dec 21 '05 #2
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.
--

Stoitcho Goutsev (100) [C# MVP]

"Omega" <om*****@gmx.net> wrote in message
news:6h********************************@4ax.com...
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

Dec 22 '05 #3
On Thu, 22 Dec 2005 09:38:05 -0500, "Stoitcho Goutsev \(100\) [C# MVP]"
<10*@100.com> wrote:
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

Dec 23 '05 #4
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.
--
HTH
Stoitcho Goutsev (100) [C# MVP]

"Omega" <om*****@gmx.net> wrote in message
news:qg********************************@4ax.com...
On Thu, 22 Dec 2005 09:38:05 -0500, "Stoitcho Goutsev \(100\) [C# MVP]"
<10*@100.com> wrote:
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

Dec 23 '05 #5

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

2 posts views Thread by Bob C. | last post: by
7 posts views Thread by Andrew Christiansen | last post: by
4 posts views Thread by Just Me | last post: by
5 posts views Thread by | last post: by
6 posts views Thread by henrycortezwu | last post: by
1 post views Thread by Sagaert Johan | last post: by
2 posts views Thread by =?Utf-8?B?S2VuTg==?= | last post: by
1 post views Thread by fmendoza | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.