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