zoukankan      html  css  js  c++  java
  • HAPPY 的魔兽争霸

    首先我们要搭建三个窗体。

    FrmLogin

    FrmRegister

    FrmMain

    2.我们先看一下第一个窗体的代码

    首先我们先双击窗体进入代码页面

    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    public UserInfo[] users=new UserInfo[10];   //创建长度为0的数组
           private void FrmLogin_Load(object sender, EventArgs e)     //双击窗体
           {
               //01.给数组的前3个位置赋值
               InitDataToArray(); 
             
           }
     
           private void InitDataToArray()    //为数组赋初值的方法
           {
               UserInfo user1=new UserInfo();     //赋值第一种方法
               user1.Uid = 1;
               user1.Uemail = "1";
               user1.Upwd = "1";
               //让游离的  user1对象    归属于  users数组
               users[0] = user1;
     
               users[1] = new UserInfo();       //赋值的第二种方法
               users[1].Uid = 2;
               users[1].Uemail = "2";
               users[1].Upwd = "2";
     
             
           }

      在双击登陆按钮

    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    private void btnLogin_Click(object sender, EventArgs e)     //双击登陆按钮
           {
               //1.0     一个标记,代表登录结果
               bool flag = false;
               //1.1     如何判定用户录入的 邮箱和  密码是正确的
               string email = txtEmail.Text;
               string pwd = txtPwd.Text;
               //1.2     循环遍历数组,依次取出每一项   item
               foreach (UserInfo item in users)
               {
                    //1.3  每一个item代表一个UserInfo对象
                   if (item!=null)
                   {
                       if (item.Uemail.Equals(email)&&item.Upwd.Equals(pwd))
                       {
                           //证明   邮箱   和密码   都是匹配的
                           flag = true;
                       }
                   }
               }
               //    1.4  除了循环,判定flag是真还是假
               if (flag==true)
               {
                   //进入主窗体
                   FrmMain frm=new FrmMain();
                   frm.email = txtEmail.Text;
                   frm.Show();
               }
               else
               {
                   MessageBox.Show("登录失败");
               }

      我们要为没有账号的用户注册账号

    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    private void llbRegist_LinkClicked(object sender,LinkLabelLinkClickedEventArgs e)   // 双击注册按钮
           {
               //01. 自身隐藏
               //this 代表的当前窗体对象  
               this.Hide();
               //02.让注册显示
               FrmRegister frm=new FrmRegister();
               frm.login = this;
               frm.Show();
           }

      第二个页面注册

    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
    55
    56
    57
    58
    59
    60
    61
    62
    63
    64
    65
    66
    67
    68
    69
    70
    71
    72
    73
    74
    75
    76
    77
    78
    79
    80
    81
    82
    83
    84
    85
    86
    87
    88
    89
    //定义窗体对象保存logininfo窗体传过来的值
    public FrmLogin fl;
    //点击注册触发的事件
    private void btnregin_Click(object sender, EventArgs e)   //双击注册战网
    {
       
        if (ProvingInfo() == true)
        {
            //获取文本框中对应的值
            string name = txtname.Text;
            string email = txtemail.Text;
            string cid = txtcid.Text;
            string password = txtpassword.Text;
            LoginInfo info = new LoginInfo();
           info.Name = name;
            info.Id = cid;
            info.Email = email;
           info.Password = password;
            MessageBox.Show("注册成功!");
            for (int i = 0; i < LoginInfo.array.Length; i++)
            {
                if (LoginInfo.array[i] == null)
                {
                    LoginInfo.array[i] = info;
                    break;
                }
            }
     
        }
    }
    //验证填写信息
    public bool ProvingInfo()
    {
         if(txtname.Text.Trim().Equals(string.Empty))
         {
             MessageBox.Show("请填写姓名");
             this.txtname.Focus();
             return false;
         }
         else if(txtcid.Text.Trim().Equals(string .Empty))
         {
             MessageBox.Show("请填身份证号码");
             this.txtcid.Focus();
             return false;
        
         }
         else if (txtemail.Text.Trim().Equals(string.Empty))
         {
             MessageBox.Show("请填身份证号码");
             this.txtemail.Focus();
             return false;
     
         }
         else if (txtpassword.Text.Trim().Equals(string.Empty))
         {
             MessageBox.Show("请填写密码");
             this.txtpassword.Focus();
             return false;
     
         }
         else if (txtone.Text.Trim().Equals(string.Empty))
         {
             MessageBox.Show("请确认邮箱输入");
             this.txtone.Focus();
             return false;
     
         }
         else if (txtokone.Text.Trim().Equals(string.Empty))
         {
             MessageBox.Show("请确认密码输入");
             this.txtokone.Focus();
             return false;
     
         }
         else if (!txtemail.Text.Equals(txtone.Text))
         {
             MessageBox.Show("两次输入的邮箱不一致");
             return false;
         }
         else if(!txtpassword.Text.Equals(txtokone.Text))
         {
          MessageBox.Show("两次输入的密码不一致");
          return false;
         }
         else
        {
            return true;
         }
      

      第三个页面显示   “欢迎你***”。

    1
    2
    3
    4
    5
    6
    7
    8
    //定义变量保存窗体传过来的值
           public string loginame;
           //Load事件
           private void FrmMain_Load(object sender, EventArgs e)  //双击窗体
           {
               //给label控件赋值
               lblloginname.Text = "欢迎" + loginame + "来到魔兽世界";
           }
  • 相关阅读:
    Spring Boot 中加载XML配置
    C#winfrom打开指定的文件
    C#怎么实现文件下载功能的四种方法
    C#查看已下载文件大小和扩展名
    C#winfrom文件下载到本地
    判断DataGridView是否选中某行
    Secure CRT注册码
    http-server 开启服
    学习网址
    angular中table表格组件的使用
  • 原文地址:https://www.cnblogs.com/xiaosedefeng/p/5325181.html
Copyright © 2011-2022 走看看