G
Guest
Hello, everyone I'm new to C# and I was wondering if someone can tell me how
do I pass a value from 1 form back to the calling routine. What I mean is in
my Parent form I have this code:
private void frmParent_Load(object sender, EventArgs e)
{
//When the form loads show the login prompt for the user to login.
Form loginForm = new frmLogin();
loginForm.ShowDialog();
}
Now in the loginform I have the following:
private bool blnFormFlag;
public bool GetFormFlag
{ get { return blnFormFlag; }
}
private void btnlogin_Click(object sender, EventArgs e)
{
bool blnLoginFlag = false;
//Check for blank username or password.
if (String.IsNullOrEmpty(txtlogin.Text)== true ||
String.IsNullOrEmpty(txtpassword.Text) == true)
{
MessageBox.Show("Blank username/password is not permitted!",
"Invalid Login", MessageBoxButtons.OK,
MessageBoxIcon.Stop);
}
else
{
sqlClass sClass = new sqlClass(); //Create sqlclass object.
//Grab flag variable.
blnLoginFlag = sClass.RequestLogin(this.txtlogin.Text,
this.txtpassword.Text);
if (blnLoginFlag == false)
MessageBox.Show("Username or password is incorrect!",
"Invalid User", MessageBoxButtons.OK,
MessageBoxIcon.Stop);
else
this.Close(); //close the form.
blnFormFlag = true;
}
}
In the calling procedure in the Parent form the method GetFormFlag isn't
made public to the object loginForm. Meaning I tried doing the following and
get an error message after I initiate the object loginForm:
private bool temp;
temp = loginForm.GetFormFlag; //not valid
How can I get the flag back to the Parent form? Thanks.
do I pass a value from 1 form back to the calling routine. What I mean is in
my Parent form I have this code:
private void frmParent_Load(object sender, EventArgs e)
{
//When the form loads show the login prompt for the user to login.
Form loginForm = new frmLogin();
loginForm.ShowDialog();
}
Now in the loginform I have the following:
private bool blnFormFlag;
public bool GetFormFlag
{ get { return blnFormFlag; }
}
private void btnlogin_Click(object sender, EventArgs e)
{
bool blnLoginFlag = false;
//Check for blank username or password.
if (String.IsNullOrEmpty(txtlogin.Text)== true ||
String.IsNullOrEmpty(txtpassword.Text) == true)
{
MessageBox.Show("Blank username/password is not permitted!",
"Invalid Login", MessageBoxButtons.OK,
MessageBoxIcon.Stop);
}
else
{
sqlClass sClass = new sqlClass(); //Create sqlclass object.
//Grab flag variable.
blnLoginFlag = sClass.RequestLogin(this.txtlogin.Text,
this.txtpassword.Text);
if (blnLoginFlag == false)
MessageBox.Show("Username or password is incorrect!",
"Invalid User", MessageBoxButtons.OK,
MessageBoxIcon.Stop);
else
this.Close(); //close the form.
blnFormFlag = true;
}
}
In the calling procedure in the Parent form the method GetFormFlag isn't
made public to the object loginForm. Meaning I tried doing the following and
get an error message after I initiate the object loginForm:
private bool temp;
temp = loginForm.GetFormFlag; //not valid
How can I get the flag back to the Parent form? Thanks.