-------简单制作魔兽登录及注册页面 窗体之间的相互跳转-------
--思路:先创建一个登录对象实体数组,然后注册信息,和初始化的用户信息存入数组中 ,进行相关的简单验证 。
第一步 :创建对像数组,实体类
class LoginInfo
{
public static LoginInfo[] array = new LoginInfo[100]; //存储登录对象
private string name;
private string pass;
private string email;
第二步:画出 窗体
登录页面

注册页面

第三步登录界面:遍历对象数组 查看文本框中的值是否匹配对象数组里的值
if (txt1.Text.Trim() == "" || txt2.Text.Trim() == "")
{
MessageBox.Show("用户名和密码不能为空", "提示");
}
else {
if (ProvingInfo() == true)
{
//定义变量接收文本框中的值
string email = txt1.Text;
string password = txt2.Text;
bool happy = false;
foreach (LoginInfo item in LoginInfo.array)
{
if (item != null)
{
if (item.Email.Equals(email) && item.Pass.Equals(password))
{
happy = true;
//关闭当前窗体
this.Hide();
//显示主窗体
FrmMain frm = new FrmMain();
frm.Show();
break;
}
}
}
if (happy == false)
{
MessageBox.Show("登录失败!请检查邮箱和密码是否正确");
}
}
第四步 :注册界面
if (txtName.Text.Trim() == "" || txtCard.Text.Trim() == "" || txtEmail.Text.Trim() == "" || txtPass.Text.Trim() == "" || txtEmailTwo.Text.Trim() == "" || txtPassTwo.Text.Trim() == "")
{
MessageBox.Show("注册信息不能为空", "提示");
}
else
{
LoginInfo info1 = new LoginInfo();
//从数组 中找到空闲位置 存储
info1.Name = txtName.Text.Trim();
info1.Pass = txtPass.Text.Trim();
info1.Email = txtEmail.Text.Trim();
MessageBox.Show(info1.Name);
MessageBox.Show("恭喜通过验证", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
for (int i = 0; i < LoginInfo.array.Length; i++)
{
if (LoginInfo.array[i] == null)
{
LoginInfo.array[i] = info1;
break;
}
}
}
}
浙公网安备 33010602011771号