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;
        }
    }
}
相关推荐
Nebula_g9 分钟前
JavaSE基础语法:特殊类(特殊情景下的设计模式)
java·开发语言·设计模式
不正经学生14 分钟前
C语言大小端字节序:内存里字节的排列顺序
c语言·开发语言·arm开发·c++·算法·c#
黑泽明*17 分钟前
LVS-Keepalived-全解析
服务器·开发语言·笔记·学习·php
动词ing27 分钟前
【C语言】命名规范
c语言·开发语言
大可-34 分钟前
Go Air 热重载安装配置指南
开发语言·后端·golang
Dovis(誓平步青云)36 分钟前
《 固井工程软件 Cemsol 的数据管理与国产化适配实践》
android·java·开发语言·人工智能
看浪的路人1 小时前
第6讲:SQL 解析器
java·开发语言·数据库
breeze jiang1 小时前
Next.js App Router 全栈实战:从 SPA 的 SEO 痛点到服务端组件与 Hydration 水合机制
开发语言·javascript·ecmascript
程序员老陆1 小时前
Qt::WidgetAttribute 常用属性详解
开发语言·qt
特立独行的猫a3 小时前
Windows安装Rust环境 Clang替代GCC MinGW环境LLVM工具链(详细教程)
开发语言·windows·rust·mingw·环境搭建·llvm