using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Windows.Forms;
partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
if ( UserIsValid( password1.Text, password2.Text ))
{
MessageBox.Show("Congratulations - they match!");
}
else
{
MessageBox.Show("They don't match - try again.");
}
}
private bool UserIsValid(string firstPassword, string secondPassword)
{
return (firstPassword == secondPassword);
}
}
partial class Form1
{
private void InitializeComponent()
{
this.label1 = new System.Windows.Forms.Label();
this.label2 = new System.Windows.Forms.Label();
this.password1 = new System.Windows.Forms.TextBox();
this.password2 = new System.Windows.Forms.TextBox();
this.button1 = new System.Windows.Forms.Button();
this.SuspendLayout();
this.label1.AutoSize = true;
this.label1.Location = new System.Drawing.Point(13, 10);
this.label1.Name = "label1";
this.label1.Size = new System.Drawing.Size(83, 14);
this.label1.TabIndex = 0;
this.label1.Text = "Enter password";
this.label2.AutoSize = true;
this.label2.Location = new System.Drawing.Point(25, 37);
this.label2.Name = "label2";
this.label2.Size = new System.Drawing.Size(71, 14);
this.label2.TabIndex = 1;
this.label2.Text = "Enter it again";
this.password1.Location = new System.Drawing.Point(103, 7);
this.password1.Name = "password1";
this.password1.Size = new System.Drawing.Size(182, 20);
this.password1.TabIndex = 2;
this.password2.Location = new System.Drawing.Point(103, 34);
this.password2.Name = "password2";
this.password2.Size = new System.Drawing.Size(182, 20);
this.password2.TabIndex = 3;
this.button1.Location = new System.Drawing.Point(210, 63);
this.button1.Name = "button1";
this.button1.TabIndex = 4;
this.button1.Text = "OK";
this.button1.Click += new System.EventHandler(this.button1_Click);
this.AutoScaleBaseSize = new System.Drawing.Size(5, 13);
this.ClientSize = new System.Drawing.Size(302, 98);
this.Controls.Add(this.button1);
this.Controls.Add(this.password2);
this.Controls.Add(this.password1);
this.Controls.Add(this.label2);
this.Controls.Add(this.label1);
this.Name = "Form1";
this.Text = "Form1";
this.ResumeLayout(false);
this.PerformLayout();
}
private System.Windows.Forms.Label label1;
private System.Windows.Forms.Label label2;
private System.Windows.Forms.TextBox password1;
private System.Windows.Forms.TextBox password2;
private System.Windows.Forms.Button button1;
}
public class PasswordFieldCompare
{
[STAThread]
static void Main()
{
Application.Run(new Form1());
}
}
23.19.Password Field |
| 23.19.1. | Password field | |
| 23.19.2. | Password fields match | |