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

A ListBox Displaying (User-)Controls

Rate me:
Please Sign up or sign in to vote.
4.55/5 (10 votes)
1 Jul 2008CPOL4 min read 62.8K   2.1K   52  
Use this Control to line up controls in a ListBox
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Text;
using System.Windows.Forms;

namespace ARBOControls {
    public delegate void AdressInfoSelected( AdressInfo AI );

    [Serializable]
    public partial class AdressInfo : UserControl, ICloneable {
        public event AdressInfoSelected OnAdressInfoSelected;
        private string kdName;
        private string tel;
        private string str;
        private string plzOrt;
        private bool selected = false;
        private Color selectedColor = Color.FromKnownColor( KnownColor.ActiveCaption );
        private Color unselectedColor;

        public Color SelectedColor {
            get { return selectedColor; }
            set { selectedColor = value; }
        }

        public bool Selected {
            get { return selected; }
            set { 
                selected = value;
                if( selected )
                    if( OnAdressInfoSelected != null )
                        OnAdressInfoSelected( this );
            }
        }

        public AdressInfo() {
            InitializeComponent();
            unselectedColor = BackColor;
        }

        public string KdName {
            get { return kdName; }
            set {
                kdName = value;
                lbName.Text = value; 
            }
        }

        public string Telefon {
            get { return tel; }
            set {
                tel = value;
                lbTel.Text = value; 
            }
        }

        public string Strasse {
            get { return str; }
            set {
                str = value;
                lbStr.Text = value; 
            }
        }

        public string PLZ_Ort {
            get { return plzOrt; }
            set {
                plzOrt = value;
                lbPlzIOrt.Text = value; 
            }
        }

        private void TextClick( object sender, EventArgs e ) {
            selected = true;
            if( OnAdressInfoSelected != null )
                OnAdressInfoSelected( this );
        }


        #region ICloneable Members

        public object Clone() {
            AdressInfo AI = new AdressInfo();
            AI.Telefon = this.tel;
            AI.KdName = this.kdName;
            AI.Strasse = this.str;
            AI.PLZ_Ort = this.plzOrt;
            AI.Tag = this.Tag;
            return AI;
        }

        #endregion
    }
}

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, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


Written By
Software Developer acs - it-systems
Germany Germany
This member has not yet provided a Biography. Assume it's interesting and varied, and probably something to do with programming.

Comments and Discussions