C# 制作简单登录页面,还挺简单的,验证密码那块你自己看需求修改,该连SQL连SQL,想明文就明文。

后来经过别人提醒,发现不用再 Form2 关闭登录窗口。直接上Code

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace Login
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        private void button1_Click(object sender, EventArgs e)
        {
            string usr = textBox1.Text;
            string psw = textBox2.Text;
            if ((usr == "Forece") & (psw == "123456"))
            {
                this.Hide();
                Form2 main = new Form2();
                main.Show();
            }
            else
            {
                MessageBox.Show("Login Failed");
            }
        }
    }
}