注册
![在这里插入图片描述](https://i-blog.csdnimg.cn/blog_migrate/ea741a1ef632c0348573b31cd08e3104.png)
private void InitializeComponent()
{
this.tb_username = 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.tb_password1 = new System.Windows.Forms.TextBox();
this.tb_password2 = new System.Windows.Forms.TextBox();
this.button1 = new System.Windows.Forms.Button();
this.button2 = new System.Windows.Forms.Button();
this.SuspendLayout();
this.tb_username.Location = new System.Drawing.Point(304, 81);
this.tb_username.Margin = new System.Windows.Forms.Padding(4);
this.tb_username.Name = "tb_username";
this.tb_username.Size = new System.Drawing.Size(348, 28);
this.tb_username.TabIndex = 0;
this.label1.AutoSize = true;
this.label1.Location = new System.Drawing.Point(84, 84);
this.label1.Margin = new System.Windows.Forms.Padding(4, 0, 4, 0);
this.label1.Name = "label1";
this.label1.Size = new System.Drawing.Size(161, 18);
this.label1.TabIndex = 2;
this.label1.Text = "Set your username";
this.label2.AutoSize = true;
this.label2.Location = new System.Drawing.Point(96, 152);
this.label2.Margin = new System.Windows.Forms.Padding(4, 0, 4, 0);
this.label2.Name = "label2";
this.label2.Size = new System.Drawing.Size(134, 18);
this.label2.TabIndex = 4;
this.label2.Text = "Enter password";
this.label3.AutoSize = true;
this.label3.Location = new System.Drawing.Point(55, 219);
this.label3.Margin = new System.Windows.Forms.Padding(4, 0, 4, 0);
this.label3.Name = "label3";
this.label3.Size = new System.Drawing.Size(233, 18);
this.label3.TabIndex = 6;
this.label3.Text = "Enter your password again";
this.tb_password1.Location = new System.Drawing.Point(304, 149);
this.tb_password1.Margin = new System.Windows.Forms.Padding(4);
this.tb_password1.Name = "tb_password1";
this.tb_password1.Size = new System.Drawing.Size(348, 28);
this.tb_password1.TabIndex = 3;
this.tb_password1.Enter += new System.EventHandler(this.tb_password1_Enter);
this.tb_password1.Leave += new System.EventHandler(this.tb_password1_Leave);
this.tb_password2.Location = new System.Drawing.Point(304, 216);
this.tb_password2.Margin = new System.Windows.Forms.Padding(4);
this.tb_password2.Name = "tb_password2";
this.tb_password2.Size = new System.Drawing.Size(348, 28);
this.tb_password2.TabIndex = 5;
this.tb_password2.Enter += new System.EventHandler(this.tb_password2_Enter);
this.tb_password2.Leave += new System.EventHandler(this.tb_password2_Leave);
this.button1.Location = new System.Drawing.Point(482, 276);
this.button1.Margin = new System.Windows.Forms.Padding(4);
this.button1.Name = "button1";
this.button1.Size = new System.Drawing.Size(170, 34);
this.button1.TabIndex = 1;
this.button1.Text = "OK!";
this.button1.UseVisualStyleBackColor = true;
this.button1.Click += new System.EventHandler(this.button1_Click);
this.button2.Location = new System.Drawing.Point(335, 344);
this.button2.Margin = new System.Windows.Forms.Padding(4);
this.button2.Name = "button2";
this.button2.Size = new System.Drawing.Size(317, 34);
this.button2.TabIndex = 1;
this.button2.Text = "Not register!Authentication!";
this.button2.UseVisualStyleBackColor = true;
this.button2.Click += new System.EventHandler(this.button2_Click);
this.AutoScaleDimensions = new System.Drawing.SizeF(9F, 18F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.ClientSize = new System.Drawing.Size(772, 456);
this.Controls.Add(this.label3);
this.Controls.Add(this.tb_password2);
this.Controls.Add(this.label2);
this.Controls.Add(this.tb_password1);
this.Controls.Add(this.label1);
this.Controls.Add(this.tb_username);
this.Controls.Add(this.button1);
this.Controls.Add(this.button2);
this.Margin = new System.Windows.Forms.Padding(4);
this.Name = "Form1";
this.Text = "Collecting keydata";
this.ResumeLayout(false);
this.PerformLayout();
}
#endregion
private System.Windows.Forms.TextBox tb_username;
private System.Windows.Forms.Label label1;
private System.Windows.Forms.Label label2;
private System.Windows.Forms.TextBox tb_password1;
private System.Windows.Forms.Label label3;
private System.Windows.Forms.TextBox tb_password2;
private System.Windows.Forms.Button button1;
private System.Windows.Forms.Button button2;
namespace Demo
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void tb_password1_Enter(object sender, EventArgs e)
{
}
private void tb_password1_Leave(object sender, EventArgs e)
{
}
private void tb_password2_Enter(object sender, EventArgs e)
{
}
private void tb_password2_Leave(object sender, EventArgs e)
{
}
private void button1_Click(object sender, EventArgs e)
{
if(……)
{
MessageBox.Show("Collecting failed! Please sign up again!");
tb_password1.Text = "";
tb_password2.Text = "";
}
else
{
MessageBox.Show("Collecting successed!");
this.DialogResult = DialogResult.OK;
this.Dispose();
this.Close();
}
}
private void button2_Click(object sender, EventArgs e)
{
this.DialogResult = DialogResult.OK;
this.Dispose();
this.Close();
}
}
}
界面跳转功能
static void Main()
{
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);
Form1 Register = new Form1();
Register.ShowDialog();
if (Register.DialogResult == DialogResult.OK)
{
Register.Dispose();
Application.Run(new Form3());
}
else if (Register.DialogResult == DialogResult.Cancel)
{
Register.Dispose();
return;
}
}
登录
![在这里插入图片描述](https://i-blog.csdnimg.cn/blog_migrate/ec6a4610a36d0eac023b0d0fe94bf3dd.png)
private void InitializeComponent()
{
this.label1 = new System.Windows.Forms.Label();
this.label2 = new System.Windows.Forms.Label();
this.tb_username = new System.Windows.Forms.TextBox();
this.tb_password = new System.Windows.Forms.TextBox();
this.button1 = new System.Windows.Forms.Button();
this.SuspendLayout();
this.label1.Location = new System.Drawing.Point(105, 92);
this.label1.Name = "label1";
this.label1.Size = new System.Drawing.Size(156, 23);
this.label1.TabIndex = 0;
this.label1.Text = "Enter username";
this.label2.Location = new System.Drawing.Point(105, 148);
this.label2.Name = "label2";
this.label2.Size = new System.Drawing.Size(156, 23);
this.label2.TabIndex = 1;
this.label2.Text = "Enter password";
this.tb_username.Location = new System.Drawing.Point(304, 87);
this.tb_username.Name = "tb_username";
this.tb_username.Size = new System.Drawing.Size(348, 28);
this.tb_username.TabIndex = 2;
this.tb_password.Location = new System.Drawing.Point(304, 149);
this.tb_password.Margin = new System.Windows.Forms.Padding(4);
this.tb_password.Name = "tb_password";
this.tb_password.Size = new System.Drawing.Size(348, 28);
this.tb_password.TabIndex = 3;
this.tb_password.Enter += new System.EventHandler(this.tb_password_Enter);
this.tb_password.Leave += new System.EventHandler(this.tb_password_Leave);
this.button1.Location = new System.Drawing.Point(429, 242);
this.button1.Margin = new System.Windows.Forms.Padding(4);
this.button1.Name = "button1";
this.button1.Size = new System.Drawing.Size(170, 34);
this.button1.TabIndex = 1;
this.button1.Text = "OK!";
this.button1.UseVisualStyleBackColor = true;
this.button1.Click += new System.EventHandler(this.button1_Click);
this.AutoScaleDimensions = new System.Drawing.SizeF(9F, 18F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.ClientSize = new System.Drawing.Size(772, 456);
this.Controls.Add(this.label1);
this.Controls.Add(this.label2);
this.Controls.Add(this.tb_username);
this.Controls.Add(this.tb_password);
this.Controls.Add(this.button1);
this.Name = "Form3";
this.Text = "Authentication";
this.ResumeLayout(false);
this.PerformLayout();
}
#endregion
private System.Windows.Forms.Label label1;
private System.Windows.Forms.Label label2;
private System.Windows.Forms.TextBox tb_username;
private System.Windows.Forms.TextBox tb_password;
private System.Windows.Forms.Button button1;
}
namespace Demo
{
public partial class Form3 : Form
{
public Form3()
{
InitializeComponent();
}
private void tb_password_Enter(object sender, EventArgs e)
{
}
private void tb_password_Leave(object sender, EventArgs e)
{
}
private void button1_Click(object sender, EventArgs e)
{
if (验证成功)
MessageBox.Show("Successed!");
else
MessageBox.Show("Failed!");
tb_password.Text = "";
}
}
}