Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Normally we <strong>don't</strong> add any child controls to a <code>Mdi Form</code>. When a <code>Form</code> is used as an <code>Mdi Form</code>, the only child it should contain is <code>MdiClient</code>. That <code>MdiClient</code> will contain your <code>child forms</code>. All the controls should be placed on the <code>Child forms</code>. However if you want so, we can still make it work</p> <p>There is a default <code>MdiClient</code> contained in a <code>Mdi Form</code>. We can find it in the <code>Controls</code> collection of the <code>Mdi Form</code>. It's type of <code>MdiClient</code>. This will be covered by all other controls of your <code>Mdi Form</code> and that's why your <code>Child forms</code> can't be brought on top by default. To solve it, simply we have to access to the <code>MdiClient</code> and call <code>BringToFont()</code> and whenever there isn't any <code>Child form</code> being <code>Visible</code>, we will call <code>SendToBack()</code> on the <code>MdiClient</code> to show the other controls of yours (button,images,label,dropdown etc). Here is the code for you to test:</p> <pre><code>public partial class Form1 : Form { public Form1() { InitializeComponent(); IsMdiContainer = true; //Find the MdiClient and hold it by a variable client = Controls.OfType&lt;MdiClient&gt;().First(); //This will check whenever client gets focused and there aren't any //child forms opened, Send the client to back so that the other controls can be shown back. client.GotFocus += (s, e) =&gt; { if (!MdiChildren.Any(x =&gt; x.Visible)) client.SendToBack(); }; } MdiClient client; //This is used to show a child form //Note that we have to call client.BringToFront(); private void ShowForm(Form childForm) { client.BringToFront();//This will make your child form shown on top. childForm.Show(); } //button1 is a button on your Form1 (Mdi container) //clicking it to show a child form and see it in action private void button1_Click(object sender, EventArgs e) { Form2 f = new Form2 { MdiParent = this }; ShowForm(f); } } </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload