'How can I control the display order of child Forms in a MDI Form

When I use an MDI Form I have a problem. My source code just like this:

private void menuItem1_Click(object sender, EventArgs e)
    {
        Form[] charr = this.MdiChildren;
        int i = 0;            
        foreach (Form chform in charr)
        {
            chform.Dock = DockStyle.Top;                
        }
        this.LayoutMdi(System.Windows.Forms.MdiLayout.TileHorizontal);
    }

The numbers of child Forms is more then 3. In order to display them correctly after the LayoutMdi() method is called, I had to set the Dock property of all child Forms to DockStyle.Top.

After calling LayoutMdi(MdiLayout.TileHorizontal), clicking the Title Bar of the first child Form, this child Form is displayed at the bottom of the MDI parent automatically.

I want that the clicked child Form maintains it's original position.
Is there any idea for this question?



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source