AddressCtl.cs
上传用户:lxycoco
上传日期:2022-07-21
资源大小:38457k
文件大小:8k
源码类别:

C#编程

开发平台:

Others

  1. using System;
  2. using System.Collections;
  3. using System.ComponentModel;
  4. using System.Drawing;
  5. using System.Data;
  6. using System.Windows.Forms;
  7. namespace UserControlSample
  8. {
  9. /// <summary>
  10. /// Summary description for UserControl1.
  11. /// </summary>
  12. public class AddressCtl : System.Windows.Forms.UserControl
  13. {
  14.     private System.Windows.Forms.TextBox txtAddress1;
  15.     private System.Windows.Forms.TextBox txtAddress2;
  16.     private System.Windows.Forms.TextBox txtCity;
  17.     private System.Windows.Forms.TextBox txtState;
  18.     private System.Windows.Forms.TextBox txtZip;
  19.     private System.Windows.Forms.Label label1;
  20.     private System.Windows.Forms.Label label2;
  21.     private System.Windows.Forms.Label label3;
  22. /// <summary>
  23. /// Required designer variable.
  24. /// </summary>
  25. private System.ComponentModel.Container components = null;
  26.     public event EventHandler AddressLine1Changed;
  27.     public event EventHandler AddressLine2Changed;
  28.     public event EventHandler CityChanged;
  29.     public event EventHandler StateChanged;
  30.     public event EventHandler ZipChanged;
  31.     
  32. public AddressCtl()
  33. {
  34. // This call is required by the Windows.Forms Form Designer.
  35. InitializeComponent();
  36. // TODO: Add any initialization after the InitComponent call
  37. }
  38. /// <summary>
  39. /// Clean up any resources being used.
  40. /// </summary>
  41. protected override void Dispose( bool disposing )
  42. {
  43. if( disposing )
  44. {
  45. if( components != null )
  46. components.Dispose();
  47. }
  48. base.Dispose( disposing );
  49. }
  50. #region Component Designer generated code
  51. /// <summary>
  52. /// Required method for Designer support - do not modify 
  53. /// the contents of this method with the code editor.
  54. /// </summary>
  55. private void InitializeComponent()
  56. {
  57.       this.txtAddress1 = new System.Windows.Forms.TextBox();
  58.       this.txtAddress2 = new System.Windows.Forms.TextBox();
  59.       this.txtCity = new System.Windows.Forms.TextBox();
  60.       this.txtState = new System.Windows.Forms.TextBox();
  61.       this.txtZip = new System.Windows.Forms.TextBox();
  62.       this.label1 = new System.Windows.Forms.Label();
  63.       this.label2 = new System.Windows.Forms.Label();
  64.       this.label3 = new System.Windows.Forms.Label();
  65.       this.SuspendLayout();
  66.       // 
  67.       // txtAddress1
  68.       // 
  69.       this.txtAddress1.Location = new System.Drawing.Point(104, 8);
  70.       this.txtAddress1.Name = "txtAddress1";
  71.       this.txtAddress1.Size = new System.Drawing.Size(192, 20);
  72.       this.txtAddress1.TabIndex = 0;
  73.       this.txtAddress1.Text = "";
  74.       this.txtAddress1.TextChanged += new System.EventHandler(this.TextBoxControls_TextChanged);
  75.       // 
  76.       // txtAddress2
  77.       // 
  78.       this.txtAddress2.Location = new System.Drawing.Point(104, 32);
  79.       this.txtAddress2.Name = "txtAddress2";
  80.       this.txtAddress2.Size = new System.Drawing.Size(192, 20);
  81.       this.txtAddress2.TabIndex = 1;
  82.       this.txtAddress2.Text = "";
  83.       this.txtAddress2.TextChanged += new System.EventHandler(this.TextBoxControls_TextChanged);
  84.       // 
  85.       // txtCity
  86.       // 
  87.       this.txtCity.Location = new System.Drawing.Point(104, 56);
  88.       this.txtCity.Name = "txtCity";
  89.       this.txtCity.TabIndex = 2;
  90.       this.txtCity.Text = "";
  91.       this.txtCity.TextChanged += new System.EventHandler(this.TextBoxControls_TextChanged);
  92.       // 
  93.       // txtState
  94.       // 
  95.       this.txtState.Location = new System.Drawing.Point(208, 56);
  96.       this.txtState.Name = "txtState";
  97.       this.txtState.Size = new System.Drawing.Size(24, 20);
  98.       this.txtState.TabIndex = 3;
  99.       this.txtState.Text = "";
  100.       this.txtState.TextChanged += new System.EventHandler(this.TextBoxControls_TextChanged);
  101.       // 
  102.       // txtZip
  103.       // 
  104.       this.txtZip.Location = new System.Drawing.Point(240, 56);
  105.       this.txtZip.Name = "txtZip";
  106.       this.txtZip.Size = new System.Drawing.Size(56, 20);
  107.       this.txtZip.TabIndex = 4;
  108.       this.txtZip.Text = "";
  109.       this.txtZip.TextChanged += new System.EventHandler(this.TextBoxControls_TextChanged);
  110.       // 
  111.       // label1
  112.       // 
  113.       this.label1.Location = new System.Drawing.Point(16, 8);
  114.       this.label1.Name = "label1";
  115.       this.label1.Size = new System.Drawing.Size(80, 20);
  116.       this.label1.TabIndex = 5;
  117.       this.label1.Text = "Address Line 1 ";
  118.       this.label1.TextAlign = System.Drawing.ContentAlignment.MiddleRight;
  119.       // 
  120.       // label2
  121.       // 
  122.       this.label2.Location = new System.Drawing.Point(16, 32);
  123.       this.label2.Name = "label2";
  124.       this.label2.Size = new System.Drawing.Size(80, 20);
  125.       this.label2.TabIndex = 6;
  126.       this.label2.Text = "Address Line 2 ";
  127.       this.label2.TextAlign = System.Drawing.ContentAlignment.MiddleRight;
  128.       // 
  129.       // label3
  130.       // 
  131.       this.label3.Location = new System.Drawing.Point(8, 56);
  132.       this.label3.Name = "label3";
  133.       this.label3.Size = new System.Drawing.Size(88, 20);
  134.       this.label3.TabIndex = 7;
  135.       this.label3.Text = "City, State && Zip ";
  136.       this.label3.TextAlign = System.Drawing.ContentAlignment.MiddleRight;
  137.       // 
  138.       // AddressCtl
  139.       // 
  140.       this.Controls.Add(this.label3);
  141.       this.Controls.Add(this.label2);
  142.       this.Controls.Add(this.label1);
  143.       this.Controls.Add(this.txtZip);
  144.       this.Controls.Add(this.txtState);
  145.       this.Controls.Add(this.txtCity);
  146.       this.Controls.Add(this.txtAddress2);
  147.       this.Controls.Add(this.txtAddress1);
  148.       this.Name = "AddressCtl";
  149.       this.Size = new System.Drawing.Size(304, 88);
  150.       this.ResumeLayout(false);
  151.     }
  152. #endregion
  153.     private void TextBoxControls_TextChanged(object sender, System.EventArgs e)
  154.     {
  155.       switch(((TextBox)sender).Name)
  156.       {
  157.         case "txtAddress1"  :
  158.           if(AddressLine1Changed != null)
  159.             AddressLine1Changed(this, EventArgs.Empty);
  160.           break;
  161.         case "txtAddress2" :
  162.           if(AddressLine2Changed != null)
  163.             AddressLine2Changed(this, EventArgs.Empty);
  164.           break;
  165.         case "txtCity" :
  166.           if(CityChanged != null)
  167.             CityChanged(this, EventArgs.Empty);
  168.           break;
  169.           case "txtState" :
  170.             if(StateChanged != null)
  171.               StateChanged(this, EventArgs.Empty);
  172.             break;
  173.           case "txtZip" :
  174.             if(ZipChanged != null)
  175.               ZipChanged(this, EventArgs.Empty);
  176.             break;
  177.       }
  178.     }
  179.     [Category("AddressData"), 
  180.     Description("Gets or sets the AddressLine1 value"),
  181.     DefaultValue("")]
  182.     public string AddressLine1
  183.     {
  184.       get{return txtAddress1.Text;}
  185.       set{
  186.         if(txtAddress1.Text != value)
  187.         {
  188.           txtAddress1.Text = value;
  189.           if(AddressLine1Changed != null)
  190.             AddressLine1Changed(this, EventArgs.Empty);
  191.         }
  192.       }
  193.     }
  194.     public string AddressLine2
  195.     {
  196.       get{return txtAddress2.Text;}
  197.       set{
  198.         if(txtAddress2.Text != value)
  199.         {
  200.           txtAddress2.Text = value;
  201.           if(AddressLine2Changed != null)
  202.             AddressLine2Changed(this, EventArgs.Empty);
  203.         }
  204.       }
  205.     }
  206.     public string City
  207.     {
  208.       get{return txtCity.Text;}
  209.       set{
  210.         if(txtCity.Text != value)
  211.         {
  212.           txtCity.Text = value;
  213.           if(CityChanged != null)
  214.             CityChanged(this, EventArgs.Empty);
  215.         }
  216.       }
  217.     }
  218.     public string State
  219.     {
  220.       get{return txtState.Text;}
  221.       set{
  222.         if(txtState.Text != value)
  223.         {
  224.           txtState.Text = value;
  225.           if(StateChanged != null)
  226.             StateChanged(this, EventArgs.Empty);
  227.         }
  228.       }
  229.     }
  230.     public string Zip
  231.     {
  232.       get{return txtZip.Text;}
  233.       set{
  234.         if(txtZip.Text != value)
  235.         {
  236.           txtZip.Text = value;
  237.           if(ZipChanged != null)
  238.             ZipChanged(this, EventArgs.Empty);
  239.         }
  240.       }
  241.     }
  242. }
  243. }