Click here to Skip to main content
15,885,278 members
Articles / Programming Languages / C#

ImageListBox - exposing localizable custom object collection as a property

Rate me:
Please Sign up or sign in to vote.
4.74/5 (15 votes)
13 Jun 20028 min read 244.3K   8K   61  
A control that exposes a custom object collection as a property that may be edited by the VS.NET Forms Designer and supports localization
using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.Data;

namespace Controls.Development
{
	/// <summary>
	/// Summary description for Form1.
	/// </summary>
	public class TestForm : System.Windows.Forms.Form
	{
        private Controls.Development.ImageListBox listBox1;
        private System.Windows.Forms.ImageList imageList1;
        private Controls.Development.ImageListBoxItem graniteItem;
        private Controls.Development.ImageListBoxItem marbleItem;
        private Controls.Development.ImageListBoxItem stoneItem;
        private Controls.Development.ImageListBoxItem stuccoItem;
        private System.ComponentModel.IContainer components;

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

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

		#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.components = new System.ComponentModel.Container();
            System.Resources.ResourceManager resources = new System.Resources.ResourceManager(typeof(TestForm));
            this.listBox1 = new Controls.Development.ImageListBox();
            this.imageList1 = new System.Windows.Forms.ImageList(this.components);
            this.graniteItem = new Controls.Development.ImageListBoxItem();
            this.marbleItem = new Controls.Development.ImageListBoxItem();
            this.stoneItem = new Controls.Development.ImageListBoxItem();
            this.stuccoItem = new Controls.Development.ImageListBoxItem();
            this.SuspendLayout();
            // 
            // listBox1
            // 
            this.listBox1.Anchor = (((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom) 
                | System.Windows.Forms.AnchorStyles.Left) 
                | System.Windows.Forms.AnchorStyles.Right);
            this.listBox1.DrawMode = System.Windows.Forms.DrawMode.OwnerDrawFixed;
            this.listBox1.ImageList = this.imageList1;
            this.listBox1.IntegralHeight = false;
            this.listBox1.ItemHeight = 18;
            this.listBox1.Items.AddRange(new Controls.Development.ImageListBoxItem[] {
                                                                                         this.graniteItem,
                                                                                         this.marbleItem,
                                                                                         this.stoneItem,
                                                                                         this.stuccoItem});
            this.listBox1.Location = new System.Drawing.Point(8, 8);
            this.listBox1.Name = "listBox1";
            this.listBox1.Size = new System.Drawing.Size(216, 80);
            this.listBox1.TabIndex = 0;
            this.listBox1.SelectedIndexChanged += new System.EventHandler(this.listBox1_SelectedIndexChanged);
            // 
            // imageList1
            // 
            this.imageList1.ColorDepth = System.Windows.Forms.ColorDepth.Depth32Bit;
            this.imageList1.ImageSize = new System.Drawing.Size(32, 16);
            this.imageList1.ImageStream = ((System.Windows.Forms.ImageListStreamer)(resources.GetObject("imageList1.ImageStream")));
            this.imageList1.TransparentColor = System.Drawing.Color.Magenta;
            // 
            // graniteItem
            // 
            this.graniteItem.ImageIndex = 0;
            this.graniteItem.Text = "Granite";
            // 
            // marbleItem
            // 
            this.marbleItem.ImageIndex = 1;
            this.marbleItem.Text = "Marble";
            // 
            // stoneItem
            // 
            this.stoneItem.ImageIndex = 2;
            this.stoneItem.Text = "Stone";
            // 
            // stuccoItem
            // 
            this.stuccoItem.ImageIndex = 3;
            this.stuccoItem.Text = "Stucco";
            // 
            // TestForm
            // 
            this.AutoScaleBaseSize = new System.Drawing.Size(5, 13);
            this.ClientSize = new System.Drawing.Size(232, 94);
            this.Controls.AddRange(new System.Windows.Forms.Control[] {
                                                                          this.listBox1});
            this.Name = "TestForm";
            this.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen;
            this.Text = "Control Test Form";
            this.ResumeLayout(false);

        }
		#endregion

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

        private void listBox1_SelectedIndexChanged(object sender, System.EventArgs e)
        {
            MessageBox.Show("The " + listBox1.Items[listBox1.SelectedIndex].Text + " has been chosen.", "Test", MessageBoxButtons.OK, MessageBoxIcon.Information);
        }
	}
}

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

License

This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here


Written By
Web Developer
United States United States
I currently work in Moscow, Russia for Boeing company.
MCSD and MCAD.NET

Comments and Discussions