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;
        }
    }
}
相关推荐
毕设源码-邱学长1 天前
【开题答辩全过程】以 基于Java的学校住宿管理系统的设计与实现为例,包含答辩的问题和答案
java·开发语言
rookieﻬ°1 天前
PHP框架漏洞
开发语言·php
玩泥巴的1 天前
存储那么贵,何不白嫖飞书云文件空间
c#·.net·二次开发·飞书
炸膛坦客1 天前
单片机/C/C++八股:(二十)指针常量和常量指针
c语言·开发语言·c++
兑生1 天前
【灵神题单·贪心】1481. 不同整数的最少数目 | 频率排序贪心 | Java
java·开发语言
炸膛坦客1 天前
单片机/C/C++八股:(十九)栈和堆的区别?
c语言·开发语言·c++
零雲1 天前
java面试:了解抽象类与接口么?讲一讲它们的区别
java·开发语言·面试
Jay_Franklin1 天前
Quarto与Python集成使用
开发语言·python·markdown
2401_831824961 天前
代码性能剖析工具
开发语言·c++·算法
是wzoi的一名用户啊~1 天前
【C++小游戏】2048
开发语言·c++