C#:登陆注册功能

注册

在这里插入图片描述

//界面
//Form1.Designer.cs

		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();
            // 
            // tb_username
            // 
            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;
            // 
            // label1
            // 
            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";
            // 
            // label2
            // 
            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";
            // 
            // label3
            // 
            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";
            // 
            // tb_password1
            // 
            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);
            // 
            // tb_password2
            // 
            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);
            // 
            // button1
            // 
            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);
            // 
            // button2
            // 
            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);
            // 
            // Form1
            // 
            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;
//功能
//Form1.cs

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)
        {
            //
        }

        //button1 完成注册
        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();
            }
        }

        //button2 已有账号,直接验证
        private void button2_Click(object sender, EventArgs e)
        {
            this.DialogResult = DialogResult.OK;
            this.Dispose();
            this.Close();
        }
    }
}

界面跳转功能

//Program.cs

		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;
            }
		}

登录

在这里插入图片描述

//界面
//Form3.Designer.cs

		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();
            // 
            // label1
            // 
            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";
            // 
            // label2
            // 
            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";
            // 
            // tb_username
            // 
            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;
            // 
            // tb_password
            // 
            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);
            // 
            // button1
            // 
            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);
            // 
            // Form3
            // 
            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;
    }
//功能
//Form3.cs

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 = "";
        }
    }
}
  • 0
    点赞
  • 6
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值