I am trying to transfer information from form B into form A. Basically formA has a button that opens a new form (form B), and then form B has a textbox where you enter text. Then when you close that form B (via a close button) a textbox in form A should be updated with text inputted in form B.
However its not working, textbox in form A is not recieving the text entered in form B, its giving me a null value.
//main class of Form A (the one that has to recieve into from Form B)
public partial class FormManager : Form
{
//creating an instance of Form B
FormContact contactForm;
public string a;
public FormManager()
{
InitializeComponent();
ControlsDisabled();
}
private void btnAdd_Click(object sender, EventArgs e)
{
//trying to fill in a textbox from form B into form A
contactForm = new FormContact();
contactForm.Show();
this.Refresh();
txtFname.Text = contactForm.fname;
//^^^the main problem, this value is null
}
private void btnEdit_Click(object sender, EventArgs e)
{
contactForm = new FormContact(txtFname.Text, txtLname.Text);
contactForm.Show();
}
//main class of form B(the form that has to give info to form A)
public partial class FormContact : Form
{
public string fname;
public string lname;
public FormContact()
{
InitializeComponent();
}
private void btnSave_Click(object sender, EventArgs e)
{
fname = txtFnameA.Text;
lname = txtLname.Text;
this.Refresh();
this.Close();
}
public FormContact(string Fname, string Lname)
{
InitializeComponent();
txtFnameA.Text = Fname;
txtLname.Text = Lname;
}
}