Search code examples
c#winformsmdi

Arranging minimised child windows on MDI


I have an MDI program with multiple child windows. Is there any way I can influence or modify the way that LayoutMdi( MdiLayout.ArrangeIcons) arranges minimised child windows in the form, or is there any way I can change the position and/or size of minimised child windows (eg in the same kind of way that I can change the position and size of the unminimised child windows using SetBounds)


Solution

  • From: https://social.msdn.microsoft.com/Forums/windows/en-US/d6014e48-2adb-4096-8bea-94c2f3b1c47c/how-to-change-the-location-of-a-minimized-mdichild-form?forum=winforms

        [DllImport("user32.dll")]
        private static extern bool SetWindowPos(IntPtr hWnd, IntPtr hWndInsertAfter, int X, int Y, int cx, int cy, uint uFlags);
    
        public FormA() {
            Button btn = new Button { Text = "asdf" };
            Controls.Add(btn);
            IsMdiContainer = true;
            var f1 = new Form { Text = "Form1", TopLevel = false, MdiParent = this};
            var f2 = new Form { Text = "Form2", TopLevel = false, MdiParent = this};
            var f3 = new Form { Text = "Form3", TopLevel = false, MdiParent = this};
            f1.Show();
            f2.Show();
            f3.Show();
            btn.Click += delegate {
                //this.LayoutMdi(MdiLayout.ArrangeIcons);
                //f1.Bounds = new Rectangle(50, 50, 100, 30);
                 int top = 100;
                 SetWindowPos(f1.Handle, IntPtr.Zero, f1.Left, top, f1.Width, f1.Height, 0);
            };
       }