zoukankan      html  css  js  c++  java
  • 魔兽世界

    第一步:先创建三个窗体,第一个登录界面,第二个是注册界面,第三个是欢迎界面

    第一个登录窗体:

    创建第二个注册窗体:

    创建第三个欢迎界面窗体:

    下面让我们来看一下关键代码,让代码带我们遨游代码的海洋:

    双击空白的区域用来写代码:

    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 + "来到魔兽世界";
           }

      

  • 相关阅读:
    Parameter Binding in ASP.NET Web API
    Which HTTP methods match up to which CRUD methods?
    ErrorHandling in asp.net web api
    HttpStatusCode
    Autofac Getting Started(默认的构造函数注入)
    Autofac Controlling Scope and Lifetime
    luvit 被忽视的lua 高性能框架(仿nodejs)
    undefined与null的区别
    VsCode中使用Emmet神器快速编写HTML代码
    字符串匹配---KMP算法
  • 原文地址:https://www.cnblogs.com/zsping/p/5333834.html
Copyright © 2011-2022 走看看