zoukankan      html  css  js  c++  java
  • 模仿魔兽登录界面 编程小练习

    工具:Visual Studio 2012

    1,首先创建一个用户登录信息类LoginInfo,并创建四个封装字段,用来保存用户信息

    2,创建登录窗体frmLogin,并编写代码,验证与用户是否登录成功

    示例代码:

    if (txtUser.Text.Trim() == "" || txtPwd.Text.Trim() == "")
    {
    MessageBox.Show("用户名或密码不能为空!", "提示");
    }
    else
    {
    string userName = txtUser.Text;
    string pwd = txtPwd.Text;
    bool isOk = false;
    foreach (LoginInfo item in array)
    {
    if (item != null)
    {
    if (item.Email == userName && item.Password == pwd)
    {
    isOk = true;
    frmMain frm = new frmMain();
    frm.txtHelloUser.Text = "欢迎," + item.Name;
    frm.Show();
    this.Hide();
    break;
    }
    }

    if (isOk == false)
    {
    txtPwd.Text = "";
    txtPwd.Focus();
    }
    }
    }

    3,创建主窗体frmMain,用户登录成功后直接跳转到主窗体,并显示欢迎+用户名

    4,创建注册窗体frmRegist,并检查信息是否合格,如果合格保存到用户信息类中

    示例代码:

    LoginInfo array = new LoginInfo();
    array.Name = txtName.Text;
    array.Id = txtId.Text;
    if (txtEmail.Text == txtCheckEmail.Text)
    {
    array.Email = txtEmail.Text;
    }
    else
    {
    array.Email = "";
    }
    if (txtPwd.Text == txtCheckPwd.Text)
    {
    array.Password = txtPwd.Text;
    }
    else
    {
    array.Password = "";
    }

    if (array.Email == "" || array.Password == "")
    {
    MessageBox.Show("密码或邮箱两次输入不一致!", "提示");
    txtPwd.Text = "";
    txtEmail.Text = "";
    txtEmail.Focus();
    }
    else
    {
    MessageBox.Show("恭喜,通过验证!","提示");
    for (int i = 0; i < fl.array.Length; i++)
    {
    if (fl.array[i] == null)
    {
    fl.array[i] = array;
    break;
    }
    }
    fl.Visible = true;
    this.Close();
    }

    好了,非常简单的一个仿的魔兽登录系统,对于IT初学者来说可以拿他练练手,还是挺有成就感的,当然也可以用类似的方法,编写英雄联盟,地下城之类的游戏登录界面!

    在家自己自娱自乐一下也是挺好的!

  • 相关阅读:
    Android手势锁实现
    网页模板pug基本语法
    React入门看这篇就够了
    我曾站在离你最近的天涯
    一文看懂浏览器事件循环
    Vi编辑网卡
    2019.6.11_MySQL进阶二:主键与外键
    2019.6.13_笔试题目及答案
    2019.6.13_MySQL简单命令的使用
    2019.6.13_SQL语句中----删除表数据drop、truncate和delete的用法
  • 原文地址:https://www.cnblogs.com/chenyang520/p/8685643.html
Copyright © 2011-2022 走看看