Image List Example : ImageList « GUI Windows Form « C# / C Sharp

C# / C Sharp
1. 2D Graphics
2. Collections Data Structure
3. Components
4. Database ADO.net
5. Development Class
6. Event
7. File Stream
8. GUI Windows Form
9. Language Basics
10. Network
11. Office
12. Regular Expressions
13. Services Event
14. Thread
15. Web Services
16. Windows
17. XML
Microsoft Office Word 2007 Tutorial
Java
Java Tutorial
Java Source Code / Java Documentation
Java Open Source
Jar File Download
Java Articles
Java Products
Java by API
C# / CSharp Tutorial
ASP.Net
JavaScript DHTML
JavaScript Tutorial
JavaScript Reference
HTML / CSS
HTML CSS Reference
C / ANSI-C
C Tutorial
C++
C++ Tutorial
PHP
Python
SQL Server / T-SQL
Oracle PL / SQL
Oracle PL/SQL Tutorial
PostgreSQL
SQL / MySQL
MySQL Tutorial
VB.Net
VB.Net Tutorial
C# / C Sharp » GUI Windows Form » ImageListScreenshots 
Image List Example
Image List Example

/*
User Interfaces in C#: Windows Forms and Custom Controls
by Matthew MacDonald

Publisher: Apress
ISBN: 1590590457
*/
using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.Data;
using System.Drawing.Drawing2D;
using System.IO;

namespace ImageListExample
{
  /// <summary>
  /// Summary description for ImageListExample.
  /// </summary>
  public class ImageListExample : System.Windows.Forms.Form
  {
    internal System.Windows.Forms.Button cmdDrawImageList;
    internal System.Windows.Forms.Button cmdFillImageList;
    /// <summary>
    /// Required designer variable.
    /// </summary>
    private System.ComponentModel.Container components = null;

    public ImageListExample()
    {
      //
      // Required for Windows Form Designer support
      //
      InitializeComponent();

      //
      // TODO: Add any constructor code after InitializeComponent call
      //
    }

    /// <summary>
    /// Clean up any resources being used.
    /// </summary>
    protected override void Disposebool disposing )
    {
      ifdisposing )
      {
        if (components != null
        {
          components.Dispose();
        }
      }
      base.Disposedisposing );
    }

    #region Windows Form Designer generated code
    /// <summary>
    /// Required method for Designer support - do not modify
    /// the contents of this method with the code editor.
    /// </summary>
    private void InitializeComponent()
    {
      this.cmdDrawImageList = new System.Windows.Forms.Button();
      this.cmdFillImageList = new System.Windows.Forms.Button();
      this.SuspendLayout();
      // 
      // cmdDrawImageList
      // 
      this.cmdDrawImageList.FlatStyle = System.Windows.Forms.FlatStyle.System;
      this.cmdDrawImageList.Location = new System.Drawing.Point(164172);
      this.cmdDrawImageList.Name = "cmdDrawImageList";
      this.cmdDrawImageList.Size = new System.Drawing.Size(9624);
      this.cmdDrawImageList.TabIndex = 3;
      this.cmdDrawImageList.Text = "Draw Images";
      this.cmdDrawImageList.Click += new System.EventHandler(this.cmdDrawImageList_Click);
      // 
      // cmdFillImageList
      // 
      this.cmdFillImageList.FlatStyle = System.Windows.Forms.FlatStyle.System;
      this.cmdFillImageList.Location = new System.Drawing.Point(28172);
      this.cmdFillImageList.Name = "cmdFillImageList";
      this.cmdFillImageList.Size = new System.Drawing.Size(10424);
      this.cmdFillImageList.TabIndex = 2;
      this.cmdFillImageList.Text = "Fill ImageList";
      this.cmdFillImageList.Click += new System.EventHandler(this.cmdFillImageList_Click);
      // 
      // ImageListExample
      // 
      this.AutoScaleBaseSize = new System.Drawing.Size(513);
      this.ClientSize = new System.Drawing.Size(292214);
      this.Controls.AddRange(new System.Windows.Forms.Control[] {
                                      this.cmdDrawImageList,
                                      this.cmdFillImageList});
      this.Name = "ImageListExample";
      this.Text = "ImageList Example";
      this.ResumeLayout(false);

    }
    #endregion

    /// <summary>
    /// The main entry point for the application.
    /// </summary>
    [STAThread]
    static void Main() 
    {
      Application.Run(new ImageListExample());
    }

    ImageList iconImages = new System.Windows.Forms.ImageList();

    private void cmdFillImageList_Click(object sender, System.EventArgs e)
    {
      // Configure the ImageList.
      iconImages.ColorDepth = System.Windows.Forms.ColorDepth.Depth8Bit;
      iconImages.ImageSize = new System.Drawing.Size(1616);
      
      // Get all the icon files in the current directory.
        string[] iconFiles = Directory.GetFiles(Application.StartupPath, "*.ico");
      
      // Create an Image object for each file and add it to the ImageList.
      // You can also use an Image subclass (like Icon).
      foreach (string iconFile in iconFiles)
      {
        Icon newIcon = new Icon(iconFile);
        iconImages.Images.Add(newIcon);
      }
         }

    private void cmdDrawImageList_Click(object sender, System.EventArgs e)
    {
      // Get the graphics device context for the form.
      Graphics g = this.CreateGraphics();
      
      // Draw each image using the ImageList.Draw() method.
      for (int i = 0; i < iconImages.Images.Count; i++)
      {
        iconImages.Draw(g, 30 + i * 3030, i);
      }
      
      // Release the graphics device context.
      g.Dispose();

    }
  }
}



           
       
ImageListExample.zip( 24 k)
Related examples in the same category
1. Add to and get Image from Image ListAdd to and get Image from Image List
w___w_w.___ja_v_a___2_s_.___c___om | Contact Us
Copyright 2003 - 08 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.