Okay, here is an example of how I would do it. On the main form on button click event:
frmSecondForm secondForm = new frmSecondForm(this); //"this" is passing the main form to the second form to be able to control the main form...
secondForm.Show();
this.Hide();
One your Second Forms constructor code:
Form frmHome;
frmSecondForm(Form callingForm) //requires a calling form to control from this form
{
Initialize(); //Already here
frmHome = callingForm as frmMain;
}
Then on the second form's closing unhide the main form:
frmSecondForm_FormClosing()
{
frmHome.Show();
}
So all in all, if you needed to pass data between the forms just add it as a parameter on the second form.
Again, I would consider placing your data collection into a repository package (folder) and class, then create a User.cs class that will hold all of the information you keep in the database.
Hint: Right click your top level item in solution explorer and go to New -> Folder. Name it Repo.
Right click that folder and go to New -> Class and name it UserRepo.
In here build functions to collect the data from the databases.
On your main form's constructor area, call the class (repo).
private Repo.UserRepo userRepo;
frmMain_FormLoad()
{
userRepo = new Repo.UserRepo();
}
Then on log in button click:
private button1_ClickEvent()
{
if(userRepo.isValidLogin(userNameText, passwordText))
{
//Do stuff
}
}
for userRepo.isValidLogin()
public bool isValidLogin(String username, String password)
{
bool isValid = false;
//Write up data code
return isValid;
}
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…