Firstly you are running code from inside the Form1 constructor, the constructor is used to initialise the form NOT run code, if you want to run code when the form is created it should be done in the Load event.
Secondly you should really send an event from the second form to any other form listing that Form2 has loaded, here is where you should signal to Form1 that it needs to hide.
And as Gerry suggested you should be using the ShowDialog() rather than Show().
Using events will solve you problems
see below
Form1 Code example
public partial class Form1 : Form
{
Form2 form2;
public Form1()
{
InitializeComponent();
Load += Form1_Load;
}
private void Form1_Load(object sender, EventArgs e)
{
if (Form1TextBox.Text == string.Empty)
{
form2 = new Form2();
form2.form2Opened += Form2HasOpened;
form2.form2Closed += Form2HasClosed;
form2.ShowDialog();
}
}
private void Form2HasOpened(object sender, EventArgs e)
{
Hide();
}
private void Form2HasClosed(object sender, EventArgs e)
{
Show();
Form1TextBox.Text = form2.Form2Data;
form2.Dispose();
}
}
Form2 Code Example
public partial class Form2 : Form
{
public event EventHandler form2Closed;
public event EventHandler form2Opened;
public Form2()
{
InitializeComponent();
Load += Form2_Load;
MyButtonClose.Click += MyButtonClose_Click;
}
private void Form2_Load(object sender, EventArgs e)
{
if (form2Opened != null)
{
form2Opened.Invoke(this, new EventArgs());
}
}
private void MyButtonClose_Click(object sender, EventArgs e)
{
Form2Data = Form2TextBox.Text;
if (form2Closed != null)
{
form2Closed.Invoke(this, new EventArgs());
}
}
public string Form2Data { get; set; }
}