In the class for form2
, create two public
class properties, one for the value of each textbox:
private String _username = null;
public String UserName { get { return _username; } }
private String _password = null;
public String Password { get { return _password; } }
In form2
you can verify and assign to properties:
private void btnOk_Click(Object sender, EventArgs e)
{
//verify if txtUser and txtPassword are correct
if (correct)
{
_username = txtUser.Text;
_password = txtPassword.Text;
}
this.Close();
}
Then you can retrieve them in your form1
code as such:
private void btnTransfer_Click(Object sender, EventArgs e)
{
//This using statement will ensure that you still have an object reference when you return from form2...
using (Form2 frmConn = new Form2())
{
frmConn.Show();
String user = frmConn.UserName;
String pass = frmConn.Password;
if (!String.IsNullOrEmpty(user) && !String.IsNullOrEmpty(pass))
//do something with them, they are valid!
}
}