I have Form1 in my application calling another form - Form2 using ShowDialog() method. After some user interaction Form2 calls its Hide() method. After that my application sometimes loses focus sometimes not. It could be some design mistake.
code extract:
public class Form1 : Form
{
Form2 form2;
public void SomeMethod()
{
if (form2==null) form2 = new Form2();
DialogResult result = form2.ShowDialog(this);
}
}
public class Form2 : Form
{
public Form2()
{
this.FormClosing += new FormClosingEventHandler(Form2_FormClosing);
}
void Form2_FormClosing(object sender, FormClosingEventArgs e)
{
if (e.CloseReason == CloseReason.UserClosing)
{
e.Cancel = true;
Hide();
}
}
}
edit: I had mistake in my code on line
DialogResult result = form2.ShowDialog(this);
was
DialogResult result = ShowDialog(form2,this);