本文转自http://www.cnblogs.com/virusswb/archive/2008/05/25/1206914.html
用户控件效果如上图
代码如下:
 using System;
using System; using System.Collections.Generic;
using System.Collections.Generic; using System.ComponentModel;
using System.ComponentModel; using System.Drawing;
using System.Drawing; using System.Data;
using System.Data; using System.Text;
using System.Text; using System.Windows.Forms;
using System.Windows.Forms;
 namespace WindowsControlLibrary1
namespace WindowsControlLibrary1 {
{ public partial class UserControl1 : UserControl
    public partial class UserControl1 : UserControl {
    { public event EventHandler AddressLine1Changed;
        public event EventHandler AddressLine1Changed; public event EventHandler AddressLine2Changed;
        public event EventHandler AddressLine2Changed; public event EventHandler ZoneChanged;
        public event EventHandler ZoneChanged; public event EventHandler NumberChanged;
        public event EventHandler NumberChanged;
 private void TextBoxControls_TextChanged(object sender, EventArgs e)
        private void TextBoxControls_TextChanged(object sender, EventArgs e) {
        { switch (((TextBox)sender).Name)
            switch (((TextBox)sender).Name) {
            { case "txtAddress1":
                case "txtAddress1": if (AddressLine1Changed != null)
                    if (AddressLine1Changed != null) {
                    { AddressLine1Changed(this, EventArgs.Empty);
                        AddressLine1Changed(this, EventArgs.Empty); }
                    } break;
                    break; case "txtAddress2":
                case "txtAddress2": if (AddressLine2Changed != null)
                    if (AddressLine2Changed != null) AddressLine2Changed(this, EventArgs.Empty);
                        AddressLine2Changed(this, EventArgs.Empty); break;
                    break; case "txtZone":
                case "txtZone": if (ZoneChanged != null)
                    if (ZoneChanged != null) ZoneChanged(this, EventArgs.Empty);
                        ZoneChanged(this, EventArgs.Empty); break;
                    break; case "txtNumber":
                case "txtNumber": if (NumberChanged != null)
                    if (NumberChanged != null) NumberChanged(this, EventArgs.Empty);
                        NumberChanged(this, EventArgs.Empty); break;
                    break; }
            } }
        } [Category("NumberData"), DescriptionAttribute("Gets or sets the Number value"), DefaultValue("")]
        [Category("NumberData"), DescriptionAttribute("Gets or sets the Number value"), DefaultValue("")] public string Number
        public string Number {
        { get { return this.txtNumber .Text; }
            get { return this.txtNumber .Text; } set
            set {
            { if (txtNumber.Text != value)
                if (txtNumber.Text != value) {
                { txtNumber.Text = value;
                    txtNumber.Text = value; if (NumberChanged != null)
                    if (NumberChanged != null) NumberChanged(this, PropertyChangedEventArgs.Empty);
                        NumberChanged(this, PropertyChangedEventArgs.Empty); }
                } }
            } }
        } [Category("AddressData"), DescriptionAttribute("Gets or sets the AddressLine1 value"), DefaultValue("")]
        [Category("AddressData"), DescriptionAttribute("Gets or sets the AddressLine1 value"), DefaultValue("")] public string AddressLine1
        public string AddressLine1 {
        { get { return txtAddress1.Text; }
            get { return txtAddress1.Text; } set
            set {
            { if (txtAddress1.Text != value)
                if (txtAddress1.Text != value) {
                { txtAddress1.Text = value;
                    txtAddress1.Text = value; if (AddressLine1Changed != null)
                    if (AddressLine1Changed != null) AddressLine1Changed(this, PropertyChangedEventArgs.Empty);
                        AddressLine1Changed(this, PropertyChangedEventArgs.Empty); }
                } }
            } }
        } [Category("AddressData"), DescriptionAttribute("Gets or sets the AddressLine2 value"), DefaultValue("")]
        [Category("AddressData"), DescriptionAttribute("Gets or sets the AddressLine2 value"), DefaultValue("")] public string AddressLine2
        public string AddressLine2 {
        { get { return txtAddress2.Text; }
            get { return txtAddress2.Text; } set
            set {
            { if (txtAddress2.Text != value)
                if (txtAddress2.Text != value) {
                { txtAddress2.Text = value;
                    txtAddress2.Text = value; if (AddressLine2Changed != null)
                    if (AddressLine2Changed != null) AddressLine2Changed(this, PropertyChangedEventArgs.Empty);
                        AddressLine2Changed(this, PropertyChangedEventArgs.Empty); }
                } }
            } }
        } [Category("ZoneData"), DescriptionAttribute("Gets or sets the Zone value"), DefaultValue("")]
        [Category("ZoneData"), DescriptionAttribute("Gets or sets the Zone value"), DefaultValue("")] public string Zone
        public string Zone {
        { get { return txtZone.Text; }
            get { return txtZone.Text; } set
            set {
            { if (txtZone.Text != value)
                if (txtZone.Text != value) {
                { txtZone.Text = value;
                    txtZone.Text = value; if (ZoneChanged!= null)
                    if (ZoneChanged!= null) ZoneChanged(this, PropertyChangedEventArgs.Empty);
                        ZoneChanged(this, PropertyChangedEventArgs.Empty); }
                } }
            } }
        } 
         
         public UserControl1()
        public UserControl1() {
        { InitializeComponent();
            InitializeComponent(); }
        } }
    } }
}
 
                     
                    
                 
                    
                 
 
        

 
     
                
            
         浙公网安备 33010602011771号
浙公网安备 33010602011771号