魔兽争霸系统

首先我们先编写魔兽系统中的用户信息类(LoginInfo)用来存放属性

封装属性代码:  

//电子邮箱 private string email;         public string Email         {             get { return email; }             set { email = value; }         }         //身份证号码 private string id;

        public string Id         {             get { return id; }             set { id = value; }         }         //姓名 private string name;

        public string Name         {             get { return name; }             set { name = value; }         }         //密码 private string password;

        public string Password         { get { return password; } set { password = value; }         }

登录界面

代码:

public static LoginInfo[] array; //创建对象数组

#region 窗体 private void FrmLogin_Load(object sender, EventArgs e)         {             //初始化用户信息               array = new LoginInfo[20];   LoginInfo infol = new LoginInfo();   infol.Name = "孙丽丽";   infol.Id = "120185198005088521";   infol.Email = "lili@sohu.com";   infol.Password = "lili1980";   array[0] = infol;

  this.lblValidation.Visible = false;         }         #endregion

        #region 登录验证 private void butLogin_Click(object sender, EventArgs e)         {   if (txtEmail.Text.Trim() == "" || txtpass.Text.Trim() == "")   {     MessageBox.Show("用户名或密码不能为空!", "提示");   }   else   {     string userName = txtEmail.Text;     string pwd = txtpass.Text;     bool isOK = false;     foreach (LoginInfo item in array)     {       if (item != null)       {         if (item.Email == userName && item.Password == pwd)         {           isOK = true;           FrmMain fm = new FrmMain();           fm.lblname.Text = "欢迎," + item.Name;           fm.Show();           this.Hide();           break;         }       }     }     if (isOK == false)     {       this.lblValidation.Visible = true;       lblValidation.Text = "用户或密码错误!";     }   }

        }         #endregion 

        #region 注册 private void linkLabel1_Click(object sender, EventArgs e)         {   FrmRegist fr = new FrmRegist();   fr.ShowDialog();         }         #endregion

        #region 关闭 private void pnlExit_Click(object sender, EventArgs e)         {   Application.Exit();         }         #endregion

        #region 窗体移动 int frmPlayX ;         int frmPlayY;         private void timer1_Tick(object sender, EventArgs e)         {   this.Location = new Point(MousePosition.X - frmPlayX, MousePosition.Y - frmPlayY);         }         private void panel1_MouseDown(object sender, MouseEventArgs e)         {   frmPlayX = e.X;   frmPlayY = e.Y;

  timer1.Enabled = true;         }         private void panel1_MouseUp(object sender, MouseEventArgs e)         {   timer1.Enabled = false;         }         #endregion

主窗体

把Lable的Modifiers改成Public直接接受登录成功以后传的值就行

注册页面

代码:

#region 注册 private void butzhuc_Click(object sender, EventArgs e)         {
  if (Bijiao()==true)   {     LoginInfo info = new LoginInfo();     info.Name = txtname.Text;     info.Id = txtId.Text;     info.Password = txtpassWord.Text;     info.Email = txtEmails.Text;

    for (int i = 1; i <= FrmLogin.array.Length; i++)     {        if (FrmLogin.array[i] == null)        {           FrmLogin.array[i] = info;           break;        }     }     this.Close(); //关闭本窗体               }         }

posted @ 2016-03-27 09:59  零星一点  阅读(473)  评论(0编辑  收藏  举报