I have two forms, one with a button ‘Add’ which loads the second form with two textboxes and a submit button.
First of all I need a way of passing the text box values to form 1 (parent) and making form 2 close on the submit..
How can I do this? Until now I have written this code but it is not working
private void button1_Click(object sender, EventArgs e)
{
emailForm EmailF = new emailForm();
if ((EmailF.Username != null && EmailF.Password != null))
{
string user = EmailF.Username;
string pass = EmailF.Password;
}
and in the emailForm.cs
private void button1_Click(object sender, EventArgs e)
{
username = username_textbox.Text;
password = username_textbox.Text;
Close();
}
public string Username
{
get { return username; }
set { this.username = value; }
}
public string Password
{
get { return password;}
set { this.password = value; }
}
You need to look at
Form.ShowDialog(). This will do what you want, and when the user closes the dialog window you can make sure they clicked “OK” (or whatever else) and then grab the values from the form.