AddressCtl.cs
上传用户:lxycoco
上传日期:2022-07-21
资源大小:38457k
文件大小:8k
- using System;
- using System.Collections;
- using System.ComponentModel;
- using System.Drawing;
- using System.Data;
- using System.Windows.Forms;
- namespace UserControlSample
- {
- /// <summary>
- /// Summary description for UserControl1.
- /// </summary>
- public class AddressCtl : System.Windows.Forms.UserControl
- {
- private System.Windows.Forms.TextBox txtAddress1;
- private System.Windows.Forms.TextBox txtAddress2;
- private System.Windows.Forms.TextBox txtCity;
- private System.Windows.Forms.TextBox txtState;
- private System.Windows.Forms.TextBox txtZip;
- private System.Windows.Forms.Label label1;
- private System.Windows.Forms.Label label2;
- private System.Windows.Forms.Label label3;
- /// <summary>
- /// Required designer variable.
- /// </summary>
- private System.ComponentModel.Container components = null;
- public event EventHandler AddressLine1Changed;
- public event EventHandler AddressLine2Changed;
- public event EventHandler CityChanged;
- public event EventHandler StateChanged;
- public event EventHandler ZipChanged;
-
- public AddressCtl()
- {
- // This call is required by the Windows.Forms Form Designer.
- InitializeComponent();
- // TODO: Add any initialization after the InitComponent call
- }
- /// <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 Component 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.txtAddress1 = new System.Windows.Forms.TextBox();
- this.txtAddress2 = new System.Windows.Forms.TextBox();
- this.txtCity = new System.Windows.Forms.TextBox();
- this.txtState = new System.Windows.Forms.TextBox();
- this.txtZip = new System.Windows.Forms.TextBox();
- this.label1 = new System.Windows.Forms.Label();
- this.label2 = new System.Windows.Forms.Label();
- this.label3 = new System.Windows.Forms.Label();
- this.SuspendLayout();
- //
- // txtAddress1
- //
- this.txtAddress1.Location = new System.Drawing.Point(104, 8);
- this.txtAddress1.Name = "txtAddress1";
- this.txtAddress1.Size = new System.Drawing.Size(192, 20);
- this.txtAddress1.TabIndex = 0;
- this.txtAddress1.Text = "";
- this.txtAddress1.TextChanged += new System.EventHandler(this.TextBoxControls_TextChanged);
- //
- // txtAddress2
- //
- this.txtAddress2.Location = new System.Drawing.Point(104, 32);
- this.txtAddress2.Name = "txtAddress2";
- this.txtAddress2.Size = new System.Drawing.Size(192, 20);
- this.txtAddress2.TabIndex = 1;
- this.txtAddress2.Text = "";
- this.txtAddress2.TextChanged += new System.EventHandler(this.TextBoxControls_TextChanged);
- //
- // txtCity
- //
- this.txtCity.Location = new System.Drawing.Point(104, 56);
- this.txtCity.Name = "txtCity";
- this.txtCity.TabIndex = 2;
- this.txtCity.Text = "";
- this.txtCity.TextChanged += new System.EventHandler(this.TextBoxControls_TextChanged);
- //
- // txtState
- //
- this.txtState.Location = new System.Drawing.Point(208, 56);
- this.txtState.Name = "txtState";
- this.txtState.Size = new System.Drawing.Size(24, 20);
- this.txtState.TabIndex = 3;
- this.txtState.Text = "";
- this.txtState.TextChanged += new System.EventHandler(this.TextBoxControls_TextChanged);
- //
- // txtZip
- //
- this.txtZip.Location = new System.Drawing.Point(240, 56);
- this.txtZip.Name = "txtZip";
- this.txtZip.Size = new System.Drawing.Size(56, 20);
- this.txtZip.TabIndex = 4;
- this.txtZip.Text = "";
- this.txtZip.TextChanged += new System.EventHandler(this.TextBoxControls_TextChanged);
- //
- // label1
- //
- this.label1.Location = new System.Drawing.Point(16, 8);
- this.label1.Name = "label1";
- this.label1.Size = new System.Drawing.Size(80, 20);
- this.label1.TabIndex = 5;
- this.label1.Text = "Address Line 1 ";
- this.label1.TextAlign = System.Drawing.ContentAlignment.MiddleRight;
- //
- // label2
- //
- this.label2.Location = new System.Drawing.Point(16, 32);
- this.label2.Name = "label2";
- this.label2.Size = new System.Drawing.Size(80, 20);
- this.label2.TabIndex = 6;
- this.label2.Text = "Address Line 2 ";
- this.label2.TextAlign = System.Drawing.ContentAlignment.MiddleRight;
- //
- // label3
- //
- this.label3.Location = new System.Drawing.Point(8, 56);
- this.label3.Name = "label3";
- this.label3.Size = new System.Drawing.Size(88, 20);
- this.label3.TabIndex = 7;
- this.label3.Text = "City, State && Zip ";
- this.label3.TextAlign = System.Drawing.ContentAlignment.MiddleRight;
- //
- // AddressCtl
- //
- this.Controls.Add(this.label3);
- this.Controls.Add(this.label2);
- this.Controls.Add(this.label1);
- this.Controls.Add(this.txtZip);
- this.Controls.Add(this.txtState);
- this.Controls.Add(this.txtCity);
- this.Controls.Add(this.txtAddress2);
- this.Controls.Add(this.txtAddress1);
- this.Name = "AddressCtl";
- this.Size = new System.Drawing.Size(304, 88);
- this.ResumeLayout(false);
- }
- #endregion
- private void TextBoxControls_TextChanged(object sender, System.EventArgs e)
- {
- switch(((TextBox)sender).Name)
- {
- case "txtAddress1" :
- if(AddressLine1Changed != null)
- AddressLine1Changed(this, EventArgs.Empty);
- break;
- case "txtAddress2" :
- if(AddressLine2Changed != null)
- AddressLine2Changed(this, EventArgs.Empty);
- break;
- case "txtCity" :
- if(CityChanged != null)
- CityChanged(this, EventArgs.Empty);
- break;
- case "txtState" :
- if(StateChanged != null)
- StateChanged(this, EventArgs.Empty);
- break;
- case "txtZip" :
- if(ZipChanged != null)
- ZipChanged(this, EventArgs.Empty);
- break;
- }
- }
- [Category("AddressData"),
- Description("Gets or sets the AddressLine1 value"),
- DefaultValue("")]
- public string AddressLine1
- {
- get{return txtAddress1.Text;}
- set{
- if(txtAddress1.Text != value)
- {
- txtAddress1.Text = value;
- if(AddressLine1Changed != null)
- AddressLine1Changed(this, EventArgs.Empty);
- }
- }
- }
- public string AddressLine2
- {
- get{return txtAddress2.Text;}
- set{
- if(txtAddress2.Text != value)
- {
- txtAddress2.Text = value;
- if(AddressLine2Changed != null)
- AddressLine2Changed(this, EventArgs.Empty);
- }
- }
- }
- public string City
- {
- get{return txtCity.Text;}
- set{
- if(txtCity.Text != value)
- {
- txtCity.Text = value;
- if(CityChanged != null)
- CityChanged(this, EventArgs.Empty);
- }
- }
- }
- public string State
- {
- get{return txtState.Text;}
- set{
- if(txtState.Text != value)
- {
- txtState.Text = value;
- if(StateChanged != null)
- StateChanged(this, EventArgs.Empty);
- }
- }
- }
- public string Zip
- {
- get{return txtZip.Text;}
- set{
- if(txtZip.Text != value)
- {
- txtZip.Text = value;
- if(ZipChanged != null)
- ZipChanged(this, EventArgs.Empty);
- }
- }
- }
- }
- }