Thanks for the thoughts BillWoodruff, I have modified the code now so that the form2 does not needs to be opened from form1 and hope this resolves the issue
1. Define the following under the form2 class
public static Form IsFormAlreadyOpen(Type FormType)
{
foreach (Form OpenForm in Application.OpenForms)
{
if (OpenForm.GetType() == FormType)
return OpenForm;
}
return null;
}
2.Add a button in form 2 and the code behind is
private void button1_Click(object sender, EventArgs e)
{
if ((Form1)IsFormAlreadyOpen(typeof(Form1)) != null)
{
var x = (Form1)IsFormAlreadyOpen(typeof(Form1));
MessageBox.Show(x.textBox1.Text);
} else {
MessageBox.Show("The forms is not opened");
}
}
3. click the button on form 2 will retrieve the value in form1 Textbox1.
This does not need the form2 to be called from form1 and returns the Textbox1 value at that time the button is clicked.
Hope this helps