Blue Theme Orange Theme Green Theme Red Theme
 
Mindcracker MVP Summit 2012
Home | Forums | Videos | Advertise | Certifications | Downloads | Blogs | Interviews | Jobs | Beginners | Training
 | Consulting  
Submit an Article Submit a Blog 
 Jump to
Skip Navigation Links
TechnologyExpand Technology
WebsiteExpand Website
6 Months Free & No Setup Fees ASP.NET Hosting!
Search :       Advanced Search »
Home » Windows Controls C# » ImageList in C#

ImageList in C#

In this article, I will discuss how to create an ImageList control and how to use its properties and methods to use in a Windows Forms application.

Author Rank :
Page Views : 16019
Downloads : 456
Rating :
 Rate it
Level : Beginner
   Print Read/Post comments Post a comment  Similar Articles  
   Email to a friend  Bookmark  Author's other articles  
Download Files:
ImageListSampleInCSharp.zip
 
 
Mindcracker MVP Summit 2012
Become a Sponsor
 Tag Cloud
 Latest Jobs
More ... 
 Latest Interview Questions
More ... 



An ImageList is a supporting control that is typically used by other controls, such as a ListView but is exposed as a component to developers. We can use this component in our applications when we are building our own controls such as a photo gallery or an image rotator control. 
In this article, I will discuss how to create an ImageList control and how to use its properties and methods to use in a Windows Forms application.

Creating an ImageList

ImageList class represents the ImageList First step to create a dynamic ImageList is to create an instance of ImageList class. The following code snippet creates an ImageList control object.

ImageList photoList = new ImageList();

 

In the next step, you may set properties of an ImageList control. The following code snippet sets a few properties of an ImageList.

photoList.TransparentColor = Color.Blue;

photoList.ColorDepth = ColorDepth.Depth32Bit;

photoList.ImageSize = new Size(200, 200);

 

Unlike other Windows Forms control, you can't add ImageList control to a Form. You need to draw an ImageList control using the Draw method. The Draw method takes a Graphics object that is the handle of the container control that will be used as a drawing canvas.

 

photoList.Draw(g, new Point(20, 20), count);


Setting ImageList Properties

ColorDepth property represents the color depth of the image list.

ImageSize property represents the size of the images in the image list.

Images property represents all images in an ImageList as an ImageCollection object.

The following code snippet sets these properties and adds three images to the ImageList control and later loops through the images and displays them on a Form.

Graphics g = Graphics.FromHwnd(this.Handle);

 

ImageList photoList = new ImageList();

photoList.TransparentColor = Color.Blue;

photoList.ColorDepth = ColorDepth.Depth32Bit;

photoList.ImageSize = new Size(200, 200);

 

photoList.Images.Add(Image.FromFile(@"C:\Images\Garden.jpg"));

photoList.Images.Add(Image.FromFile(@"C:\Images\Tree.jpg"));

photoList.Images.Add(Image.FromFile(@"C:\Images\Waterfall.jpg"));

 

for (int count = 0; count < photoList.Images.Count; count++)

{

    photoList.Draw(g, new Point(20, 20), count);

 

    // Paint the form and wait to load the image

    Application.DoEvents();

    System.Threading.Thread.Sleep(1000);

}

 

Summary
In this article, we discussed discuss how to create and use an ImageList control in a Windows Forms application.

Comment Request!
Thank you for reading this post. Please post your feedback, question, or comments about this post Here.
Login to add your contents and source code to this article
 [Top] Rate this article
 
 About the author
 
Mahesh Chand
Mahesh is the founder of C# Corner and Mindcracker Network, an author of several .NET programming books and a Microsoft MVP for 6 consecutive years. In his day to day work, Mahesh is a Senior Software Consultant with over 14 years of IT industry experience building systems for Financial and Banking, Engineering & Architectural, Imaging, Construction, Biological & Pharmaceuticals, Healthcare and Education industries. His expertise is Windows Forms, ASP.NET, Silverlight, WPF, WCF, Visual Studio 2010, SQL Server, and Oracle.  If you are looking for a Sharepoint, Windows Forms, ASP.NET, WPF, Silverlight, C#, VB.NET, Oracle, and SQL Server Consultant in Philadelphia area or remote location, drop me a line at MAHESH [AT] C-SHARPCORNER [DOT] COM.
Looking for C# Consulting?
C# Consulting is founded in 2002 by the founders of C# Corner. Unlike a traditional consulting company, our consultants are well-known experts in .NET and many of them are MVPs, authors, and trainers. We specialize in Microsoft .NET development and utilize Agile Development and Extreme Programming practices to provide fast pace quick turnaround results. Our software development model is a mix of Agile Development, traditional SDLC, and Waterfall models.
Click here to learn more about C# Consulting.
 
Introducing MaxV - one click. infinite control. Hyper-V Hosting from MaximumASP.
Finally – a virtual platform that delivers next-generation Windows Server 2008 Hyper-V virtualization technology from a managed hosting partner you can truly depend on. Visit www.maximumasp.com/max for a FREE 30 day trial. Hurry offer ends soon. Climb aboard the MaxV platform and take advantage of High Availability, Intelligent Monitoring, Recurrent Backups, and Scalability – with no hassle or hidden fees. As a managed hosting partner focused solely on Microsoft technologies since 2000, MaximumASP is uniquely qualified to provide the superior support that our business is built on. Unparalleled expertise with Microsoft technologies lead to working directly with Microsoft as first to offer IIS 7 and SQL 2008 betas in a hosted environment; partnering in the Go Live Program for Hyper-V; and product co-launches built on WS 2008 with Hyper-V technology.
Dynamic PDF
ceTE software specializes in components for dynamic PDF generation and manipulation. The DynamicPDF™ product line allows you to dynamically generate PDF documents, merge PDF documents and new content to existing PDF documents from within your applications.
Discover the top 5 tips for understanding .NET
Ricky Leeks presents the top 5 tips for understanding .NET Interoperability. Learn more.
Nevron Chart for .NET 2010.1 Now Available
The leading .NET charting control now features PDF, Flash and Silverlight export, visualization of large datasets and more. Deliver true charting functionality to your BI, Scorecard, Presentation or Scientific apps. Download evaluation now.
ASP.NET 4 Hosting
Get 2 Months Free of ASP.NET Hosting for Only $4.95/month! Receive FREE MS SQL and MySQL Databases Including ASP.NET 4/3.5, MVC 3.0, Silverlight 4, Windows 2008/IIS 7.0 Plus FREE IIS 7 Modules. Host UNLIMITED ASP.NET Web Sites – Click Here!
 
 Post a Feedback, Comment, or Question about this article
Subject:
Comment:
Nevron Chart
Become a Sponsor
 Comments
creation of dynamic controls by venkat On July 20, 2010
can u please send me how to create dynamic controls, fetching events and more exampls on dynamic controls

plz
regards
venkat
9502675656
Reply | Email | Modify 
Re: creation of dynamic controls by Mahesh On August 15, 2010
Venkat,
Go to Windows Controls section of this site (home page >> Left side bar >> Click Windows Controls) or go to my profile page. I have written articles on most of the controls that includes both design-time and run-time creation of controls and set their properties and call their methods.

Cheers!
Reply | Email | Modify 
Image List Problem by Ei Cho On August 7, 2010
I do as u say. But the images are not shown in Form. Image Path is okay. I want to know why? Please reply me. Thank a lot.
Reply | Email | Modify 
Re: Image List Problem by Mahesh On August 15, 2010
Did you download the attached project? Download it, change your image path and run it. It is a VS 2010 project.

For testing, you can drag and drop and ImageList onto a Form and add images to it at design time and check the path code code behind.

Reply | Email | Modify 
FeedBack to articles by Jinal On December 5, 2011
Hi Mahesh It always cool to view your code as it helped me a lot and even at times its the same what i was looking for. Would be glad to make you a friend and hope you would like it too. Looking forward for your reply. Regards
Reply | Email | Modify 
Iis server by Rehan On January 30, 2012
Iis server making debug problm.so kindly solutn on rehanpq@gmail.com
Reply | Email | Modify 
Nevron Chart
 © 2012  contents copyright of their authors. Rest everything copyright Mindcracker. All rights reserved.