namespace AddressBook { using System; using System.Windows.Forms; using System.Drawing; class EntryButton : Button { public EntryButton(String myText) { this.Text = myText; } public void SetParams(Size mySize , Point myPoint) { this.Size = mySize; this.Location = myPoint; } } class EntryLabel : Label { public EntryLabel(String myText) { this.Text = myText; this.AutoSize = true; } public void SetLocation(Point myPoint , int myTabIndex) { this.Location = myPoint; this.TabIndex = myTabIndex; } } class EntryText : TextBox { public EntryText(String myText) { this.Text = myText; } public void SetParams(Point myPoint , int myTabIndex) { this.Size = new Size(200,20); this.TabIndex = myTabIndex; this.Location = myPoint; } } //Usage of get / set public class AddressEntry : Form { public String FirstName { get { return txtFirstName.Text; } set { txtFirstName.Text = value; } } public String LastName { get { return txtLastName.Text; } set { txtLastName.Text = value; } } public String EMail { get { return txtEMail.Text; } set { txtEMail.Text = value; } } public String PhoneNumber { get { return txtPhone.Text; } set { txtPhone.Text = value; } } private EntryText txtFirstName; private EntryText txtLastName; private EntryText txtEMail; private EntryText txtPhone; private EntryLabel lblFirstName; private EntryLabel lblLastName; private EntryLabel lblEMail; private EntryLabel lblPhone; private EntryButton btnSaveButton; private EntryButton btnCancelButton; public AddressEntry() { this.Text = "Address Entry"; this.StartPosition = FormStartPosition.CenterScreen; this.FormBorderStyle = FormBorderStyle.FixedDialog; this.MaximizeBox = false; this.MinimizeBox = false; this.ClientSize = new Size(330,227); lblFirstName = new EntryLabel("First Name"); lblFirstName.SetLocation(new Point(16,16),0); this.Controls.Add(lblFirstName); lblLastName = new EntryLabel("Last Name"); lblLastName.SetLocation(new Point(16,56),2); this.Controls.Add(lblLastName); lblEMail = new EntryLabel("E Mail Address"); lblEMail.SetLocation(new Point(16,96),4); this.Controls.Add(lblEMail); lblPhone = new EntryLabel("Phone Number"); lblPhone.SetLocation(new Point(16,136),6); this.Controls.Add(lblPhone); txtFirstName = new EntryText(""); txtFirstName.SetParams(new Point(100,12),1); this.Controls.Add(txtFirstName); txtLastName = new EntryText(""); txtLastName.SetParams(new Point(100,52),3); this.Controls.Add(txtLastName); txtEMail = new EntryText(""); txtEMail.SetParams(new Point(100,92),5); this.Controls.Add(txtEMail); txtPhone = new EntryText(""); txtPhone.SetParams(new Point(100,132),7); this.Controls.Add(txtPhone); btnSaveButton = new EntryButton("Save"); btnSaveButton.SetParams(new Size(88,32),new Point(120,170)); btnSaveButton.Click += new EventHandler(onSave); this.Controls.Add(btnSaveButton); btnCancelButton = new EntryButton("Close"); btnCancelButton.DialogResult = DialogResult.Cancel; btnCancelButton.SetParams(new Size(88,32) , new Point(220,170)); btnCancelButton.Click += new EventHandler(onCancel); this.Controls.Add(btnCancelButton); this.AcceptButton = btnSaveButton; this.CancelButton = btnCancelButton; } protected void onCancel(Object mySender , EventArgs myArgs) { this.Close(); } protected void onSave(Object mySender , EventArgs myArgs) { if(txtFirstName.Text.Trim() == "") { MessageBox.Show("Please enter the First Name","AddressBook 1.0",MessageBoxButtons.OK , MessageBoxIcon.Error); txtFirstName.Focus(); } else if(txtLastName.Text.Trim() == "") { MessageBox.Show("Please enter the Last Name","AddressBook 1.0",MessageBoxButtons.OK , MessageBoxIcon.Error); txtLastName.Focus(); } else if(txtEMail.Text.Trim() == "") { MessageBox.Show("Please enter the E-Mail Address","Address Book 1.0",MessageBoxButtons.OK , MessageBoxIcon.Error); txtEMail.Focus(); } else if(txtPhone.Text.Trim() == "") { MessageBox.Show("Please enter the Phone Number","Address Book 1.0",MessageBoxButtons.OK , MessageBoxIcon.Error); txtPhone.Focus(); } else { this.Close(); } } } }