Jesus Ramos Jesus Ramos - 3 months ago 24
C# Question

C# Windows forms cascading windows

I currently have a menu button that allows users to open a new dialog which I would like to be placed directly to the right of the main form. The user can open as many of these dialogs as they would like but I would like them to cascade on top of the first dialog that they opened (if there is one). I've seen ways to do something similar using an MdiLayout but this is just for normal dialogs.

Answer

Do you want to loop through all the open dialogs, setting each windows location?

this.Location = new Point(x,y);

or

int prevHeight =0;
foreach (Form f in this.OwnedForms)
{
x += 5;
y += prevHeight;
f.Location = new Point(x, y);
prevHeight += f.Height;
}