Reputation:
Is it possible to make that when child window is opened, parent window is minimized and is inactive (child window is modal)? I tried changing WindowState property to minimized for parent window before calling child window, but then child window starts minimized.
Upvotes: 2
Views: 4141
Reputation: 2007
Not sure why you want to do it this way, but this is doable with some trickery (or good design patterns). With trickery you can do this:
From parent (form1):
private void button1_Click(object sender, EventArgs e)
{
this.WindowState = FormWindowState.Minimized;
this.ShowInTaskbar = false;
new Form2().ShowDialog(this);
this.WindowState = FormWindowState.Normal;
this.ShowInTaskbar = true;
}
Although, I would recommend reconsidering your architecture instead.
Upvotes: 2
Reputation: 612794
There is a flaw in your design.
You have two top-level Windows, the main form and the child modal dialog. The child modal dialog is what is known as, in Win32 terminology, an owned window. The main form is un-owned. When a top-level un-owned Window is minimized, all the windows that it owns are hidden. That is functionality provided by the desktop window manager.
The documentation states:
An owned window is hidden when its owner is minimized.
What you are trying to do sounds unusual anyway. Normally when a form shows a modal dialog, the modal dialog is shown on top of the other form. Why are you wanting to hide the main form?
If you are dead-set on this design you need to arrange that your modal dialog is an un-owned window. When you do so it will appear as an item in the taskbar separate from your main form. Is this what you want?
Upvotes: 0
Reputation: 1183
In the child form_Load event, try this :
frmParent frm = new frmParent();
frm.WindowState = FormWindowState.Minimized;
Upvotes: -1