C# Winform制作一个登录系统

cs 复制代码
using System;
using System.Collections;
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 登录
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
           
        }
        public ArrayList UserName=new ArrayList();
        public ArrayList Password=new ArrayList();
        private void button2_Click(object sender, EventArgs e)
        {
            if(textBox1.Text == "")
            {
                label4.Text = "账号不能为空";
                label4.ForeColor = Color.Red;
                return;
            }
            if(textBox2.Text =="")
            {
                label4.Text = "";
                label5.Text = "密码不能为空";
                label5.ForeColor = Color.Red;
                return;
            }
            label5.Text = "";
            bool IsEdit=false;
            for(int i = 0; i < UserName.Count; i++)
            {
                if((string)UserName[i] ==textBox1.Text)
                {
                    IsEdit = true;
                    break;  
                }
            }
            if(IsEdit)
            {
                MessageBox.Show("账号已注册");
              
            }
            else
            {
                MessageBox.Show("账号注册成功");
                UserName.Add(textBox1.Text);
                Password.Add(textBox2.Text);
                //textBox1.Clear();
                //textBox2.Clear();
            }
        }

        private void button1_Click(object sender, EventArgs e)
        {
            bool isSiccess = false;
            for (int i = 0; i < UserName.Count; i++)
            {

                if (textBox1.Text.Equals(UserName[i]) && textBox2.Text.Equals(Password[i]))
                {
                    isSiccess = true;
                    break;
                }
            }
            if (isSiccess)
            {
                    Form2 form2 = new Form2();
                    form2.Show();
                    this.Hide();
                
            }
            else
            {
                MessageBox.Show("账号或密码错误");
            }
        }

        private void button3_Click(object sender, EventArgs e)
        {
            this.Close();
        }

        private void textBox1_KeyDown(object sender, KeyEventArgs e)
        {
            
            if (e.KeyCode == Keys.Enter)
            {
                this.textBox2.Focus();
            }
        }

        private void textBox2_KeyPress(object sender, KeyPressEventArgs e)
        {
            if(e.KeyChar==(char)Keys.Enter)
            {
                this.button1_Click(sender, e);
            }
        }
    }
}
cs 复制代码
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 登录
{
    public partial class Form2 : Form
    {
        public Form2()
        {
            InitializeComponent();
          

        }
        

        private void button1_Click(object sender, EventArgs e)
        {
            Label label = new Label();
            label.Text = "Suprise!";
            label.Font = new Font("微软雅黑", 70);
            label.ForeColor = Color.Red;
            label.Location = new Point(180, 200);
            label.AutoSize = true;
            label.ImageAlign = ContentAlignment.MiddleCenter;
            this.Controls.Add(label);
            button1.Visible = false;
        }
    }
}
相关推荐
lsx20240619 分钟前
Eclipse 添加书签
开发语言
易营宝27 分钟前
高效的跨境电商广告优化系统:易营宝广告投放实操指南
大数据·开发语言·人工智能·php
superman超哥30 分钟前
路由的艺术:Rust Web 框架中的高效匹配与类型安全提取
开发语言·rust·编程语言·rust web框架·rust路由
hqwest35 分钟前
码上通QT实战22--趋势页面01-准备图表对象
开发语言·qt·qpainter·qss·painevent·qt绘图事件
hqwest1 小时前
码上通QT实战23--趋势页面02-图表模拟数据
开发语言·qt·qpainter·qt绘图·绘制曲线
Echo缘1 小时前
关于在.cpp文件中包含c的头文件,编译报错问题
c语言·开发语言
人道领域1 小时前
【零基础学java】(反射)
java·开发语言
ghie90901 小时前
GPS抗干扰算法MATLAB实现
开发语言·算法·matlab
ytttr8731 小时前
基于MATLAB解决车辆路径问题(VRP)
开发语言·matlab
沛沛老爹2 小时前
Web开发者突围AI战场:Agent Skills元工具性能优化实战指南——像优化Spring Boot一样提升AI吞吐量
java·开发语言·人工智能·spring boot·性能优化·架构·企业开发