Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / Languages / C# / December 2005

Tip: Looking for answers? Try searching our database.

A global ImageList ?

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Omega - 21 Dec 2005 15:56 GMT
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
Ben Dewey - 21 Dec 2005 17:34 GMT
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.
Stoitcho Goutsev (100) [C# MVP] - 22 Dec 2005 14:38 GMT
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.

Signature

Stoitcho Goutsev (100) [C# MVP]

> Hi,
>
[quoted text clipped - 5 lines]
>
> Thanks
Omega - 23 Dec 2005 09:36 GMT
On Thu, 22 Dec 2005 09:38:05 -0500, "Stoitcho Goutsev \(100\) [C# MVP]"
<100@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
Stoitcho Goutsev (100) [C# MVP] - 23 Dec 2005 15:52 GMT
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.

Signature

HTH
Stoitcho Goutsev (100) [C# MVP]

> On Thu, 22 Dec 2005 09:38:05 -0500, "Stoitcho Goutsev \(100\) [C# MVP]"
> <100@100.com> wrote:
[quoted text clipped - 26 lines]
>
> Omega

Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.