0
我的教师给了我和我的同学三项活动,这些活动是使用注册表单做一个简单的登录表单而不使用数据库(很明显,我们需要做这个活动与数据库)继续.....之前不使用数据库的登录表单和注册表格
这里是代码: Form1中:
public partial class Form1 : Form
{
string Username;
string Password;
string NAME;
string Age;
Form2 Frm = new Form2();
//Here is where you get the value of the String from Form2
public void PassValue(string strValue)
{
Username = strValue;
}
public void PassAnotherValue(string strValue2)
{
Password = strValue2;
}
public void PassAnotherValueAgain(string strValue3)
{
NAME = strValue3;
}
public void PassAnotherValueAgainAndAgain(string strvalue4)
{
Age = strvalue4;
}
//------------------------------------------------------------------
public Form1()
{
InitializeComponent();
}
private void LoginBtn_Click(object sender, EventArgs e)
{
if (string.IsNullOrWhiteSpace(LoginUserNameTB.Text))
{
MessageBox.Show("Please input proper Username...!");
}
if (string.IsNullOrWhiteSpace(LoginPasswordTB.Text))
{
MessageBox.Show("Please input proper Password...!");
}
else if ((LoginUserNameTB.Text != Username) && (LoginPasswordTB.Text != Password))
{
MessageBox.Show("Welcome" + NAME + "!");
}
else if ((LoginUserNameTB.Text == Username) && (LoginPasswordTB.Text == Password))
{
MessageBox.Show("Please input proper Username and/or Password...!");
}
}
private void RegisterBtn1_Click(object sender, EventArgs e)
{
Frm.Show();
}
}
}
窗体2:
//Form2 has four textboxes, four labels, and a button
private void RegisterBtn2_Click(object sender, EventArgs e)
{
Form1 obj1 = new Form1();
Form1 obj2 = new Form1();
Form1 obj3 = new Form1();
Form1 obj4 = new Form1();
Form1 obj5 = new Form1();
//This is where you pass the String value back to Form1
obj1.PassValue(RegUserNameTB.Text);
obj2.PassAnotherValue(RegPasswordTB.Text);
obj3.PassAnotherValueAgain(NTB.Text);
obj4.PassAnotherValueAgainAndAgain(ATB.Text);
if (string.IsNullOrWhiteSpace(NTB.Text) && string.IsNullOrWhiteSpace(ATB.Text) && string.IsNullOrWhiteSpace(RegUserNameTB.Text) && string.IsNullOrWhiteSpace(RegPasswordTB.Text))
{
MessageBox.Show("Please enter the following:" + "\n" + "Name" + "\n" + "Age" + "\n" + "\n" + "UserName" + "\n" + "Password");
}
Close();
}
}
}
现在到这个程序的问题..... 该程序工作得很好,每次我输入用户名和密码它的工作,但'名称'的价值是缺失的,每次我点击注册按钮它只会执行一次动作,而不会再次执行(可能需要一个例外)....并且总结起来,我们的教师告诉我们用户将有3个输入用户名和密码的限制,然后程序将关闭....任何想法?
你为什么要创建5'Form1中()'对象的用户相匹配? – FrankerZ