C#实现系统登录

 1, 新建窗口frm_Login

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 WindowsFormsApp1
{
    public partial class Form_Login : Form
    {
        string Pwd = "";
        public Form_Login()//构造函数
        {
            InitializeComponent();
        }

        private void button1_Click(object sender, EventArgs e)
        {
            
            //string name = this.textBox_name.Text;
            //string pwd = this.textBox_pwd.Text;

            Form frm_login = new Form_Login();


            if (Pwd == this.textBox_pwd.Text)
            {
                if (MessageBox.Show("登录成功!") == DialogResult.OK)
                {
                    //Form frm_socket = new Form_Socket();
                    //frm_socket.ShowDialog();//打开该界面后,无法操作其他界面;
                    //frm_socket.Show();//打开该界面后,可以操作其他界面;;
                }
            }
            else
            {
                MessageBox.Show("密码错误!");
            }
        }


        private void comboBox_name_SelectedIndexChanged(object sender, EventArgs e)
        {
            if (comboBox_name.SelectedIndex==0)//操作员索引值=0
            {
                Pwd = "000";
            }
            else if (comboBox_name.SelectedIndex == 1)//维护员索引值=1
            {
                Pwd = "111";
            }
            else if (comboBox_name.SelectedIndex == 2)//管理员索引值=2
            {
                Pwd = "222";
            }
        }

        private void button_exit_Click(object sender, EventArgs e)
        {
            this.Close();//关闭当前窗口
            //Application.Exit();//关闭应用程序;
        }

        private void Form_Login_Load(object sender, EventArgs e)
        {
            comboBox_name.SelectedIndex = 0;//窗口加载时执行默认用户
        }
    }

}

 

posted @ 2024-09-15 22:34  CSF践行  阅读(31)  评论(0编辑  收藏  举报