I have a form that launches formB. I would like forma to be hidden until formb is closed. There may be a change formb is opened by formC and others so i simply cant just create a new form. Is there a way to launch formB, hide and block until close?
+6
A:
This should do it.
this.Visible = false;
using (formB as new FormB())
formB.ShowDialog(this);
this.Visible = true;
SchlaWiener
2010-07-11 11:18:29
Doesn't work, the main window will get hidden behind the window of another app.
Hans Passant
2010-07-11 14:41:19
Hmmm, try calling ShowDialog() without a parameter.
SchlaWiener
2010-07-11 16:42:19
A:
You can use the OnActivate
event to hide the owner and the Dispose
event to show the owner. This solution works even if form_b isn't called from another form:
Code in form_x:
FormB f = new FormB();
f.Show(this);
Code in form_b
this.Activated += new System.EventHandler(this.HideOwner);
private void HideOwner(object sender, EventArgs e)
{
if (this.Owner != null) this.Owner.Hide();
}
protected override void Dispose(bool disposing)
{
if (this.Owner != null) this.Owner.Show();
if (disposing && (components != null))
{
components.Dispose();
}
base.Dispose(disposing);
}
Anax
2010-07-11 11:49:39